Message ID | 20231006201719.work.356-kees@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp573868vqo; Fri, 6 Oct 2023 13:17:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1NfGVrNbcW2qfXRmCpqEQZIswciasJSEImzoXTYMkuv94MpoqSGl7DO6ewwB1OCT26PhD X-Received: by 2002:a05:6a20:4292:b0:13f:c40c:379 with SMTP id o18-20020a056a20429200b0013fc40c0379mr11116362pzj.13.1696623468135; Fri, 06 Oct 2023 13:17:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696623468; cv=none; d=google.com; s=arc-20160816; b=p3HnzuWv49B501Qoy5JlpNX3CD+GX6/v0n3eI+A2F7DjLDURhBGNtKe295bGSTy8ls uwMThTvK21IGxgyQIZv4PhWd6dBVCXYdjllPg0rM9TOb+Wi8LB+Hor8MxLFwV/8P/DE/ cpVtNOHxjfMmeCiiv5f02d62ZbR9nijRl4fRo6oUnAi22ZALS+EIjCdJ2jbVnL/MZX3Q 6Yed9NVS4XUj1dmbolRvfPNH2njP2S6g4qedw6/1fwO43yZcYAHTp8nbRCLxxZ0YpmoN PrNvbrVWtbdN/7omhDtXjwncn4sPMrCSjdFMtX6mGEAVzw3Eqg86E6brcMdryDte6uuM tdKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=kW97lFtdi7tQSx5WV0UdX/3taJs5J9htbLPAyylMrXE=; fh=e1X09+f1vC935LzNUFrXo3aG4SsSqb2y3hBfUDrWDWw=; b=kLvVM9P019YSMmHx0FGfL6N9wzkjOBWJaoXBjIqsyr3D4UcARjTsw9UElkUr+Hhrf8 aT7+zHuTaeK+Lh0aaHL1QyMlH7X9+aqr6gLWif/cD5+g0Vj/pQwZlqxP6qcrl7FNep9c 3uLiCXeAB9G0KDQUkI1dE4ATMPMpSov2NrZi5loeM9Qusua+ajShjQCNcohDc3RyGmgi c6MT7s3fdEIzTIk+2PF/EeFzdi/VWFKKXJEMeT5blWM3vBxitjkw04JUhN2SoBQgwEa4 WnL7J9LVRGE+uXN8ox83giCcJ9x0ll9ncaeJKMttFUGrwYSRfxCyg8SeuNNeJ/w6ergR kr7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kJfSleHI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id bu15-20020a056a00410f00b0068e4358d041si2149182pfb.175.2023.10.06.13.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 13:17:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kJfSleHI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 71F8F809FA4D; Fri, 6 Oct 2023 13:17:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233443AbjJFURc (ORCPT <rfc822;ezelljr.billy@gmail.com> + 18 others); Fri, 6 Oct 2023 16:17:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233476AbjJFUR2 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 6 Oct 2023 16:17:28 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C12A9FA for <linux-kernel@vger.kernel.org>; Fri, 6 Oct 2023 13:17:24 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-690ba63891dso2152524b3a.2 for <linux-kernel@vger.kernel.org>; Fri, 06 Oct 2023 13:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696623443; x=1697228243; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=kW97lFtdi7tQSx5WV0UdX/3taJs5J9htbLPAyylMrXE=; b=kJfSleHIr4K5rV9AG0993UM4ty3EhIbt+f1zqjQPQATref/U78mlNCHrRB2PdId8Ap rhMUfyWUb428Sj2BvkML1y1A/7QkCp2Op73EBLONKDC5PJfN6WU/1uP2e6ODanPf2sO6 PfJVx9hocwMqsuqGyF0UB6KAQYv9A7WlZEcn0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696623443; x=1697228243; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kW97lFtdi7tQSx5WV0UdX/3taJs5J9htbLPAyylMrXE=; b=u9Mga0g5ktsyH0lr3Go7JO6Wy5QLBaU9N6KnNKIhWqU6VrpkyTJwlRT3CL3eX6N+i3 MJN/c7v2PGaMHCt1UQzBt4uvVGpBvz68JNfZAFfli7nFxbyBKCvqaTKklxurujvScU/V wcDFiNIjBMe9i+EBywO5nOT3a1SFPkbIaXLdhxdyIEfEaWEBkqRngjdqwPelVwkh/KH7 OFPd15AdanbWP/RIkPHbJOaPULMd8pRlXDV4pXPeHjhQ5i7MRK1C93YD6Ag7U3ESHGyu vAlTDYmEwMCG7hbcPIKjltZ4T51udBCGcAqBFvHKE11cTLIgZHhStgkvAqMsdBDjeYH4 3o7Q== X-Gm-Message-State: AOJu0Yy2WC4qD+xxYGlPSTwMb++flpESQ77Y/PDLBIENoHXM+USj/I5W wqsBhzwssjmM9+ByDtlyNLpMvw== X-Received: by 2002:a05:6a21:3296:b0:140:d536:d428 with SMTP id yt22-20020a056a21329600b00140d536d428mr10800853pzb.51.1696623443148; Fri, 06 Oct 2023 13:17:23 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id q16-20020a62ae10000000b0069343e474bcsm1886916pff.104.2023.10.06.13.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 13:17:22 -0700 (PDT) From: Kees Cook <keescook@chromium.org> To: Christian Lamparter <chunkeey@googlemail.com> Cc: Kees Cook <keescook@chromium.org>, Kalle Valo <kvalo@kernel.org>, "Gustavo A. R. Silva" <gustavoars@kernel.org>, linux-wireless@vger.kernel.org, linux-hardening@vger.kernel.org, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Tom Rix <trix@redhat.com>, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] wifi: p54: Annotate struct p54_cal_database with __counted_by Date: Fri, 6 Oct 2023 13:17:20 -0700 Message-Id: <20231006201719.work.356-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1282; i=keescook@chromium.org; h=from:subject:message-id; bh=NFwzX0Eq7KCDbbQM5umu2p/6j6lMwTY9c2gIIvIyXH8=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlIGtQu26M1sSthhYbE6kdTUaJiSm4LeUxUUykm 4fh5mQO3aaJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZSBrUAAKCRCJcvTf3G3A Jhn3D/9y8+XILyj+byVNV0fCgmz3v95DGYn0tJmv1MXslgAFu8Pww0V8y65fznB07xphjUv3cxA WEudhs5dA2oWKVPIwgQkBr3dHpfR7MfTVAMX10JUODoUvZVbazlu7hg0b1/7JFv1xtmuwolgPFU ZDLr+eXAHNGcBC7mQDHWoQhR/anMut6KlTh0STekS1k9UApNKth4ayj4Q27n6URT7tgcLyhTpXG IDqWi7pmZhV0HTzbN3qJ9OzS8Ea6Mrr3flfaApdtgc8l4Q8/KxLtO+gbQgWTd5bSAhG8ee3BrW7 CbghSKSSzyymAfdDTmw0xrvj6qfi+fTNEnOC/ahuDL/gsc+OPa/JbiLIWhLqhF5tOPKrwtvEPWQ zaUV5mYkSplYev71JajAiT3XxdTIy4NvIAHvwhdz6qakMmuIPeWdxXVsF30xALAoGqwA4LUljcE rOKtVVsTzIf3yZNJhOzFzBwOZlf6gpiSCfX/WLCn9+84Xf44KcnkWmIOrAJp8v85wuBKsOa3FGh 7TVCgeR/pe2oepKBwd24/KIQfu00XLzyQ7gliBRqobRTqowyK+UH4HCz6dW8TJ9+xF/1MBlohwB xWPTCxRzak2H8nyD8d/6psRG4kwCNICHXBCHdZ2sggZ3np+yS6sngN07u5+GoFUfkOBP2trZMya Y8XV3hQ JBRA4ZRg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 06 Oct 2023 13:17:45 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779038650100094651 X-GMAIL-MSGID: 1779038650100094651 |
Series |
wifi: p54: Annotate struct p54_cal_database with __counted_by
|
|
Commit Message
Kees Cook
Oct. 6, 2023, 8:17 p.m. UTC
Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for
array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).
As found with Coccinelle[1], add __counted_by for struct p54_cal_database.
Cc: Christian Lamparter <chunkeey@googlemail.com>
Cc: Kalle Valo <kvalo@kernel.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-wireless@vger.kernel.org
Cc: linux-hardening@vger.kernel.org
Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
Signed-off-by: Kees Cook <keescook@chromium.org>
---
drivers/net/wireless/intersil/p54/p54.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 10/6/23 22:17, Kees Cook wrote: > Prepare for the coming implementation by GCC and Clang of the __counted_by > attribute. Flexible array members annotated with __counted_by can have > their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for > array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family > functions). > > As found with Coccinelle[1], add __counted_by for struct p54_cal_database. > > Cc: Christian Lamparter <chunkeey@googlemail.com> > Cc: Kalle Valo <kvalo@kernel.org> > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> > Cc: linux-wireless@vger.kernel.org > Cc: linux-hardening@vger.kernel.org > Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1] > Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Thanks!
Hi, I randomly peeked at this patch. Unfortunately, I am not familiar with the actual p54 code. On Fri, Oct 6, 2023 at 4:17 PM Kees Cook <keescook@chromium.org> wrote: > > Prepare for the coming implementation by GCC and Clang of the __counted_by > attribute. Flexible array members annotated with __counted_by can have > their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for > array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family > functions). > > As found with Coccinelle[1], add __counted_by for struct p54_cal_database. > > Cc: Christian Lamparter <chunkeey@googlemail.com> > Cc: Kalle Valo <kvalo@kernel.org> > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> > Cc: linux-wireless@vger.kernel.org > Cc: linux-hardening@vger.kernel.org > Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1] > Signed-off-by: Kees Cook <keescook@chromium.org> > --- > drivers/net/wireless/intersil/p54/p54.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/wireless/intersil/p54/p54.h b/drivers/net/wireless/intersil/p54/p54.h > index 3356ea708d81..770e348d1f6c 100644 > --- a/drivers/net/wireless/intersil/p54/p54.h > +++ b/drivers/net/wireless/intersil/p54/p54.h > @@ -126,7 +126,7 @@ struct p54_cal_database { > size_t entry_size; > size_t offset; > size_t len; > - u8 data[]; > + u8 data[] __counted_by(entries); This looks incorrect - I think you want __counted_by(len)? The presence of entry_size made me suspicious. > }; This is the function that creates struct p54_cal_database: static struct p54_cal_database *p54_convert_db(struct pda_custom_wrapper *src, size_t total_len) { struct p54_cal_database *dst; size_t payload_len, entries, entry_size, offset; payload_len = le16_to_cpu(src->len); entries = le16_to_cpu(src->entries); entry_size = le16_to_cpu(src->entry_size); offset = le16_to_cpu(src->offset); if (((entries * entry_size + offset) != payload_len) || (payload_len + sizeof(*src) != total_len)) return NULL; dst = kmalloc(sizeof(*dst) + payload_len, GFP_KERNEL); if (!dst) return NULL; dst->entries = entries; dst->entry_size = entry_size; dst->offset = offset; dst->len = payload_len; memcpy(dst->data, src->data, payload_len); return dst; } You can see that kmalloc is performed with `sizeof(*dst) + payload_len`, and payload_len is assigned to ->len. I don't read Coccinelle, but, if this patch was auto-generated, I wonder if the script has an error. Regards, Jason
On 10/9/23 16:55, Jason Andryuk wrote: > Hi, > > I randomly peeked at this patch. Unfortunately, I am not familiar > with the actual p54 code. > > On Fri, Oct 6, 2023 at 4:17 PM Kees Cook <keescook@chromium.org> wrote: >> >> Prepare for the coming implementation by GCC and Clang of the __counted_by >> attribute. Flexible array members annotated with __counted_by can have >> their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for >> array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family >> functions). >> >> As found with Coccinelle[1], add __counted_by for struct p54_cal_database. >> >> Cc: Christian Lamparter <chunkeey@googlemail.com> >> Cc: Kalle Valo <kvalo@kernel.org> >> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> >> Cc: linux-wireless@vger.kernel.org >> Cc: linux-hardening@vger.kernel.org >> Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1] >> Signed-off-by: Kees Cook <keescook@chromium.org> >> --- >> drivers/net/wireless/intersil/p54/p54.h | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/net/wireless/intersil/p54/p54.h b/drivers/net/wireless/intersil/p54/p54.h >> index 3356ea708d81..770e348d1f6c 100644 >> --- a/drivers/net/wireless/intersil/p54/p54.h >> +++ b/drivers/net/wireless/intersil/p54/p54.h >> @@ -126,7 +126,7 @@ struct p54_cal_database { >> size_t entry_size; >> size_t offset; >> size_t len; >> - u8 data[]; >> + u8 data[] __counted_by(entries); > > This looks incorrect - I think you want __counted_by(len)? The I think you're right. More comments below... > presence of entry_size made me suspicious. > >> }; > > This is the function that creates struct p54_cal_database: > > static struct p54_cal_database *p54_convert_db(struct pda_custom_wrapper *src, > size_t total_len) > { > struct p54_cal_database *dst; > size_t payload_len, entries, entry_size, offset; > > payload_len = le16_to_cpu(src->len); > entries = le16_to_cpu(src->entries); > entry_size = le16_to_cpu(src->entry_size); > offset = le16_to_cpu(src->offset); > if (((entries * entry_size + offset) != payload_len) || > (payload_len + sizeof(*src) != total_len)) > return NULL; > > dst = kmalloc(sizeof(*dst) + payload_len, GFP_KERNEL); > if (!dst) > return NULL; > > dst->entries = entries; > dst->entry_size = entry_size; > dst->offset = offset; > dst->len = payload_len; > > memcpy(dst->data, src->data, payload_len); > return dst; > } > > You can see that kmalloc is performed with `sizeof(*dst) + > payload_len`, and payload_len is assigned to ->len. This should be changed to: - dst = kmalloc(sizeof(*dst) + payload_len, GFP_KERNEL); + dst = kmalloc(struct_size(dst, data, payload_len), GFP_KERNEL); > > I don't read Coccinelle, but, if this patch was auto-generated, I > wonder if the script has an error. With the struct_size() change, the Coccinelle script should be able to generate a correct patch for this. -- Gustavo
On Mon, Oct 09, 2023 at 10:55:32AM -0400, Jason Andryuk wrote: > Hi, > > I randomly peeked at this patch. Unfortunately, I am not familiar > with the actual p54 code. > > On Fri, Oct 6, 2023 at 4:17 PM Kees Cook <keescook@chromium.org> wrote: > > > > Prepare for the coming implementation by GCC and Clang of the __counted_by > > attribute. Flexible array members annotated with __counted_by can have > > their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for > > array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family > > functions). > > > > As found with Coccinelle[1], add __counted_by for struct p54_cal_database. > > > > Cc: Christian Lamparter <chunkeey@googlemail.com> > > Cc: Kalle Valo <kvalo@kernel.org> > > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> > > Cc: linux-wireless@vger.kernel.org > > Cc: linux-hardening@vger.kernel.org > > Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1] > > Signed-off-by: Kees Cook <keescook@chromium.org> > > --- > > drivers/net/wireless/intersil/p54/p54.h | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/net/wireless/intersil/p54/p54.h b/drivers/net/wireless/intersil/p54/p54.h > > index 3356ea708d81..770e348d1f6c 100644 > > --- a/drivers/net/wireless/intersil/p54/p54.h > > +++ b/drivers/net/wireless/intersil/p54/p54.h > > @@ -126,7 +126,7 @@ struct p54_cal_database { > > size_t entry_size; > > size_t offset; > > size_t len; > > - u8 data[]; > > + u8 data[] __counted_by(entries); > > This looks incorrect - I think you want __counted_by(len)? The > presence of entry_size made me suspicious. > > > }; > > This is the function that creates struct p54_cal_database: > > static struct p54_cal_database *p54_convert_db(struct pda_custom_wrapper *src, > size_t total_len) > { > struct p54_cal_database *dst; > size_t payload_len, entries, entry_size, offset; > > payload_len = le16_to_cpu(src->len); > entries = le16_to_cpu(src->entries); > entry_size = le16_to_cpu(src->entry_size); > offset = le16_to_cpu(src->offset); > if (((entries * entry_size + offset) != payload_len) || > (payload_len + sizeof(*src) != total_len)) > return NULL; > > dst = kmalloc(sizeof(*dst) + payload_len, GFP_KERNEL); > if (!dst) > return NULL; > > dst->entries = entries; > dst->entry_size = entry_size; > dst->offset = offset; > dst->len = payload_len; > > memcpy(dst->data, src->data, payload_len); > return dst; > } > > You can see that kmalloc is performed with `sizeof(*dst) + > payload_len`, and payload_len is assigned to ->len. Agreed! > I don't read Coccinelle, but, if this patch was auto-generated, I > wonder if the script has an error. Yeah, I'm not sure which part went wrong. I will investigate. Thanks for catching this!
On Mon, Oct 09, 2023 at 10:55:32AM -0400, Jason Andryuk wrote: > This is the function that creates struct p54_cal_database: > > static struct p54_cal_database *p54_convert_db(struct pda_custom_wrapper *src, > size_t total_len) > { > struct p54_cal_database *dst; > size_t payload_len, entries, entry_size, offset; > > payload_len = le16_to_cpu(src->len); > entries = le16_to_cpu(src->entries); > entry_size = le16_to_cpu(src->entry_size); > offset = le16_to_cpu(src->offset); > if (((entries * entry_size + offset) != payload_len) || > (payload_len + sizeof(*src) != total_len)) > return NULL; > > dst = kmalloc(sizeof(*dst) + payload_len, GFP_KERNEL); > if (!dst) > return NULL; > > dst->entries = entries; > dst->entry_size = entry_size; > dst->offset = offset; > dst->len = payload_len; > > memcpy(dst->data, src->data, payload_len); > return dst; > } > > You can see that kmalloc is performed with `sizeof(*dst) + > payload_len`, and payload_len is assigned to ->len. > > I don't read Coccinelle, but, if this patch was auto-generated, I > wonder if the script has an error. It seems that my Coccinelle script got confused by this: p54_convert_output_limits(): priv->output_limit = kmalloc(data[1] * sizeof(struct pda_channel_output_limit) + sizeof(*priv->output_limit), GFP_KERNEL); ... priv->output_limit->entry_size = sizeof(struct pda_channel_output_limit); priv->output_limit->len = priv->output_limit->entry_size * priv->output_limit->entries + priv->output_limit->offset; It thought "sizeof(struct pda_channel_output_limit)" was the element count, since it wasn't able to identify the array member here. Regardless, I've sent a v2 now. :)
diff --git a/drivers/net/wireless/intersil/p54/p54.h b/drivers/net/wireless/intersil/p54/p54.h index 3356ea708d81..770e348d1f6c 100644 --- a/drivers/net/wireless/intersil/p54/p54.h +++ b/drivers/net/wireless/intersil/p54/p54.h @@ -126,7 +126,7 @@ struct p54_cal_database { size_t entry_size; size_t offset; size_t len; - u8 data[]; + u8 data[] __counted_by(entries); }; #define EEPROM_READBACK_LEN 0x3fc