Message ID | 20221129092002.3538384-1-Ilia.Gavrilov@infotecs.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp234010wrr; Tue, 29 Nov 2022 01:44:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf75q1DMPWf+c380JCSiieOPsi7Jzw7FRdwnbZ/LCa4A0lyJMhoIzYKQl2OncOOE2Tr+CsVz X-Received: by 2002:a17:906:298c:b0:7c0:7d08:bfc with SMTP id x12-20020a170906298c00b007c07d080bfcmr5647358eje.72.1669715089318; Tue, 29 Nov 2022 01:44:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669715089; cv=none; d=google.com; s=arc-20160816; b=b5oE2FecN0jsNv6+Vqc7/JUrHdU1imybQVborpeUQMhi8YzJ+JIkC20VVEkk41VqLF Ir/yeJGRg6decgXXuXPzHbQSHSa6kYsBkPuRZJcfLMBWXEUOg9nXUEbZjPCGoF2/dzTP wIS7JY9nNklPda3A1RTk2RN/f9pCDKgLyFP11NyB8rQ0g33959p7jp17ShKoC9h0BHjy a68fSc+hJtB6ohXDUkvV+cHrr9v8resI8OBstWc2arpxSVW2MyDuMzWeRK9OzfUxs3S5 +G1JXQNkZs3iP/RIyebQDSUHZAFO9EMIZUm3T1IsWRhpTiYYFDtFMXaeWNRGy+gXHMdA P8KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature:dkim-filter; bh=34cO/GV9E8UjUhEC8QC8GWzLPIeTkL25yYRQJuX+RJo=; b=SgogGyb4ukd962OzW/Se6OHU5Dy8gHFEE11srRB7YAR+8TXV3e7hGiBa5cF9DqM9/D WlAjAGlIbEaUmtI8G3feZZe+nCWmbcvFzLREmeAh/lar3/HrCBr5PO2cRlF2TyWtc3Ct BETKaNRC5nJyf2EJTDmCc1SXS1LaV4mrgY1gIUJx7KleLyXUi87xObkEfyYCO+JghP7I smCO5KhRNRJu3VP09a5MQTR2QPbsSZgVkga2Hlpi/mT5SrZbgJZCucMLM9L2VvWhKGTT Ve32FbM9LgpMHCoi9iHTnx7XKFRjncnIYpLXmwfkqXLlBza72NjiXUkgpfUlSEXKIheM fUjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infotecs.ru header.s=mx header.b=wNXwNb2P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=infotecs.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a14-20020a05640213ce00b0046b1d405d4asi4966553edx.206.2022.11.29.01.44.23; Tue, 29 Nov 2022 01:44:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infotecs.ru header.s=mx header.b=wNXwNb2P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=infotecs.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230358AbiK2J3h (ORCPT <rfc822;rbbytesnap@gmail.com> + 99 others); Tue, 29 Nov 2022 04:29:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231838AbiK2J3Z (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 29 Nov 2022 04:29:25 -0500 X-Greylist: delayed 335 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 29 Nov 2022 01:29:18 PST Received: from mx0.infotecs.ru (mx0.infotecs.ru [91.244.183.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A0C45C759 for <linux-kernel@vger.kernel.org>; Tue, 29 Nov 2022 01:29:18 -0800 (PST) Received: from mx0.infotecs-nt (localhost [127.0.0.1]) by mx0.infotecs.ru (Postfix) with ESMTP id A26311206575; Tue, 29 Nov 2022 12:23:38 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx0.infotecs.ru A26311206575 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=infotecs.ru; s=mx; t=1669713819; bh=34cO/GV9E8UjUhEC8QC8GWzLPIeTkL25yYRQJuX+RJo=; h=From:To:CC:Subject:Date:From; b=wNXwNb2PyZlCiXVoV0zKPn7PzUo6VPMGh5pnGxcAWqDJIjVYM2N9e/qfpR2mJ+T7G 809eDYORrDSuCmMXodchd8NgtOFf6iZCuzsOZn1PvDVtHqI2rgSejZYXcy5D6yBg15 69h5dAPnu5OlJeAL/rMFUJjt7pm7w5g/bsH4Gsig= Received: from msk-exch-01.infotecs-nt (msk-exch-01.infotecs-nt [10.0.7.191]) by mx0.infotecs-nt (Postfix) with ESMTP id 955A130CCD5E; Tue, 29 Nov 2022 12:23:38 +0300 (MSK) Received: from msk-exch-01.infotecs-nt (10.0.7.191) by msk-exch-01.infotecs-nt (10.0.7.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.12; Tue, 29 Nov 2022 12:23:38 +0300 Received: from msk-exch-01.infotecs-nt ([fe80::89df:c35f:46be:fd07]) by msk-exch-01.infotecs-nt ([fe80::89df:c35f:46be:fd07%14]) with mapi id 15.02.1118.012; Tue, 29 Nov 2022 12:23:38 +0300 From: Gavrilov Ilia <Ilia.Gavrilov@infotecs.ru> To: Andrew Morton <akpm@linux-foundation.org> CC: Gavrilov Ilia <Ilia.Gavrilov@infotecs.ru>, Colin Ian King <colin.i.king@gmail.com>, wuchi <wuchi.zero@gmail.com>, Jens Axboe <axboe@kernel.dk>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>, "lvc-project@linuxtesting.org" <lvc-project@linuxtesting.org> Subject: [PATCH] relay: Fix type mismatch when allocating memory in relay_create_buf() Thread-Topic: [PATCH] relay: Fix type mismatch when allocating memory in relay_create_buf() Thread-Index: AQHZA9RDQYv1MYkRoUybHQ6EQG7cLA== Date: Tue, 29 Nov 2022 09:23:38 +0000 Message-ID: <20221129092002.3538384-1-Ilia.Gavrilov@infotecs.ru> Accept-Language: ru-RU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.17.0.10] x-exclaimer-md-config: 208ac3cd-1ed4-4982-a353-bdefac89ac0a Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-KLMS-Rule-ID: 1 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Lua-Profiles: 173812 [Nov 29 2022] X-KLMS-AntiSpam-Version: 5.9.59.0 X-KLMS-AntiSpam-Envelope-From: Ilia.Gavrilov@infotecs.ru X-KLMS-AntiSpam-Rate: 0 X-KLMS-AntiSpam-Status: not_detected X-KLMS-AntiSpam-Method: none X-KLMS-AntiSpam-Auth: dkim=none X-KLMS-AntiSpam-Info: LuaCore: 502 502 69dee8ef46717dd3cb3eeb129cb7cc8dab9e30f6, {Tracking_from_domain_doesnt_match_to}, infotecs.ru:7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;127.0.0.199:7.1.2 X-MS-Exchange-Organization-SCL: -1 X-KLMS-AntiSpam-Interceptor-Info: scan successful X-KLMS-AntiPhishing: Clean, bases: 2022/11/29 05:53:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2022/11/29 04:55:00 #20623102 X-KLMS-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750823169067825173?= X-GMAIL-MSGID: =?utf-8?q?1750823169067825173?= |
Series |
relay: Fix type mismatch when allocating memory in relay_create_buf()
|
|
Commit Message
Gavrilov Ilia
Nov. 29, 2022, 9:23 a.m. UTC
The 'padding' field of the 'rchan_buf' structure is an array of 'size_t'
elements, but the memory is allocated for an array of 'size_t *' elements.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: b86ff981a825 ("[PATCH] relay: migrate from relayfs to a generic relay API")
Signed-off-by: Ilia.Gavrilov <Ilia.Gavrilov@infotecs.ru>
---
kernel/relay.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On Tue, 29 Nov 2022 09:23:38 +0000 Gavrilov Ilia <Ilia.Gavrilov@infotecs.ru> wrote: > The 'padding' field of the 'rchan_buf' structure is an array of 'size_t' > elements, but the memory is allocated for an array of 'size_t *' elements. > > Found by Linux Verification Center (linuxtesting.org) with SVACE. > > --- a/kernel/relay.c > +++ b/kernel/relay.c > @@ -148,13 +148,13 @@ static struct rchan_buf *relay_create_buf(struct rchan *chan) > { > struct rchan_buf *buf; > > - if (chan->n_subbufs > KMALLOC_MAX_SIZE / sizeof(size_t *)) > + if (chan->n_subbufs > KMALLOC_MAX_SIZE / sizeof(size_t)) > return NULL; > > buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL); > if (!buf) > return NULL; > - buf->padding = kmalloc_array(chan->n_subbufs, sizeof(size_t *), > + buf->padding = kmalloc_array(chan->n_subbufs, sizeof(size_t), > GFP_KERNEL); This is why I prefer kmalloc_array(N, sizeof(*(buf->padding)), ...) Because the reviewer doesn't have to go check that the types match up, and because the code doesn't need changing if the type of *(buf->padding) is changed. Others don't like this practice, but I forget why.
diff --git a/kernel/relay.c b/kernel/relay.c index d7edc934c56d..88bcb09f0a1f 100644 --- a/kernel/relay.c +++ b/kernel/relay.c @@ -148,13 +148,13 @@ static struct rchan_buf *relay_create_buf(struct rchan *chan) { struct rchan_buf *buf; - if (chan->n_subbufs > KMALLOC_MAX_SIZE / sizeof(size_t *)) + if (chan->n_subbufs > KMALLOC_MAX_SIZE / sizeof(size_t)) return NULL; buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL); if (!buf) return NULL; - buf->padding = kmalloc_array(chan->n_subbufs, sizeof(size_t *), + buf->padding = kmalloc_array(chan->n_subbufs, sizeof(size_t), GFP_KERNEL); if (!buf->padding) goto free_buf;