Message ID | 20230922175424.work.863-kees@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5912564vqi; Fri, 22 Sep 2023 15:58:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFNb6AE/jzncr77zqopb8guzMrd9SeHK8PQFHBLn6EgCXEJmclcU020pfoMYJLppc7UtW4l X-Received: by 2002:a05:6870:d24b:b0:1d6:617d:62eb with SMTP id h11-20020a056870d24b00b001d6617d62ebmr937063oac.39.1695423514815; Fri, 22 Sep 2023 15:58:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695423514; cv=none; d=google.com; s=arc-20160816; b=gIUfr5Kenz0ZVbipExdHGyWStsHP1XM6K5EpCWpOgN4ARlSMjKAWOUKesfamRZK04K tSotMz0rjlQZyXI4hqcc3fMlJcLAnh/HuJc458D5srH2m/gkN4izSVKwZEk/6MuuuZwL 0EUDf/nvNFQXR8z/sqymX7PP/sic4zLwyMZe1vlcOOx5BUFv5L6/2dOEwBUZVZF0eHFX h6gFvH1ZReInFcxpFLarvzw3B3HfJjAH17g9heMpg1ceLYATC9ez/eGzFnMNWuYY4NRK V9S46zfOn3qA3E1hPY1TFjacPr+CNd8+HnbJyPHvq65Yzc2ln6JXP55EgJ2HNfVSDZDq an+w== 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=j+EF4vJBkJk+ZVR9CblihV9KVKwpbDqXkhI36zKUO6c=; fh=kP1EjA5Tx/LRrTU8cFU22oerZs7PabU70NsIbUBUvsg=; b=ZghxORkeufs+32qqEuZhcpGJZQHtpk1sx+Xts1/cgQ8WcLPlkMifyBIC0lBnGMZD1S bZnUDJvqMbsvneUtClbFlp2py/DxOGya340KgALnmJ0055rhZ1jKJ/+7MbPzjziXaXX1 7hz74G2COKAwLTs3cnhHo5ZG6yTt1FsxUgoQTsWkcwIxEv2erziKwJ3D8RY7wm87X5wM jNXYQSQ7aQQRNc5rqjlKlVySnHXWz1mZV+SyD1tDlWU7yhFAZH2YfW43pTdeIUbWv/mU zuJodu8zyOHANV0qtcrvh+BeWhstD2KPo+o/jd/9UEEkwI7DE+vWnb4s45C0InaA6ygF /Nqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="kLcYT/Ll"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id b20-20020a656694000000b0056a77ae0b55si4545245pgw.458.2023.09.22.15.58.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 15:58:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="kLcYT/Ll"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 1841883D5051; Fri, 22 Sep 2023 10:56:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233829AbjIVR4c (ORCPT <rfc822;pwkd43@gmail.com> + 28 others); Fri, 22 Sep 2023 13:56:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233961AbjIVR4I (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 22 Sep 2023 13:56:08 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C300410EC for <linux-kernel@vger.kernel.org>; Fri, 22 Sep 2023 10:54:27 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2767378ae15so1745725a91.1 for <linux-kernel@vger.kernel.org>; Fri, 22 Sep 2023 10:54:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695405267; x=1696010067; 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=j+EF4vJBkJk+ZVR9CblihV9KVKwpbDqXkhI36zKUO6c=; b=kLcYT/LllAUOWPyeCaorT9YFh0fumN7IpfIOstAMpbLCIqfT1UOG+3iaCV8NAoeDWO zV5svidS8VKtsGNVgp5rphF2FvKVA+o+vZ2t3/jpBYjQdTgs6W61mhh4v6NzFrh7LI5c 5C7oCVD6sNJ2k3jzfrL/jVGkcqSacZScVEtws= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695405267; x=1696010067; 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=j+EF4vJBkJk+ZVR9CblihV9KVKwpbDqXkhI36zKUO6c=; b=MqHuvcIdKQv8etkYPEA/isO+dxkgDtBqVOB/nFpdB3TM7RvgE3CrcQVtMSfT0deYpN LGgGpRYtcnbpsRjKJhhXFcNrA9T4+t7Lj1X3luBeB4L6DrEvH2iRw+XpO82VJHP35RQV A+swVXZm0IVF1Lz+5Anc5L8ws3TkLAaGYxEgPOfK96tLNmuXkjWHXUOmR8tl1QWY8BPg EYBHSp8sfL9j3xTTMbnBQMAf0ViwvZJE/S5UpLC0xGTTBTarSqdRC6gslYgX7xKlisG4 7QP20qurNatz0YOU8ov3GXJ1qlUEyhw5EAfPlUEAJ1VTHgDf8CYQ7+y0jFeJEO8okBeU PxJw== X-Gm-Message-State: AOJu0Yw0FOSaabNoUSjjD4s2iAkEps/APMFNrame6onJTl6Bsk+XODAk eTvZNW+nCBX5dDWVtd9lBRtOoA== X-Received: by 2002:a17:90a:c7d2:b0:26b:4e40:7be8 with SMTP id gf18-20020a17090ac7d200b0026b4e407be8mr425881pjb.12.1695405267155; Fri, 22 Sep 2023 10:54:27 -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 4-20020a17090a098400b00274a9f8e82asm5621422pjo.51.2023.09.22.10.54.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 10:54:26 -0700 (PDT) From: Kees Cook <keescook@chromium.org> To: Wolfram Sang <wsa@kernel.org> Cc: Kees Cook <keescook@chromium.org>, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>, Luca Ceresoli <luca.ceresoli@bootlin.com>, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Tom Rix <trix@redhat.com>, linux-i2c@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] media: i2c: Annotate struct i2c_atr with __counted_by Date: Fri, 22 Sep 2023 10:54:25 -0700 Message-Id: <20230922175424.work.863-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1312; i=keescook@chromium.org; h=from:subject:message-id; bh=xHqAexkdir++JtYVtYwcT7l23jrkf39UFVqFNHYvTUM=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlDdTROjZmn9PrBfPmIbpkMcg5sdNYLw8r0dJEE dRDF6P38uuJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZQ3U0QAKCRCJcvTf3G3A JmMlEACyXQMycy4pimGfzQlMXVi/e5YP4/RoKKXxI3rA+mIRz/OEaWUNy187GNrPLMuVRUEl6+m 7HBRBE5xxKe03wBcUu0kmWdpDuLIN0efMNzsWH2PQY8YPDw1V7Gaeh5FHD+MTY9xp+88FCZq0dw O5fNNwnBpaiJ8q+hwyak4O84zmGhnxy/Mo7yPZMWaq4nFn8IbqprfKnjorcedYUuWWHfJQ1wkzN HoR3w0l8YapoHDkp1vCqhdfExasn72Qu0UgN/n4xVTJckAJ0+UYYw9s3DpLvqRzSi0PTgN67ypb MtWf6E0kk2TN113KyScBCSU9h6D6uo0uRSZvt8PrTi2J50/IftiSoNkwY2w3DuBxqu28vd+lJJz sWfGFrp0lfdEIb5YqkIWT1BUxW6nD1VcLLfUWD1zneBljOu5GXct0D3g342AYe0F3g8u2LpXzH0 uVG/7sBg/wHslmjgTJWx+VpOXkqbGue5ZH4PhIzc7kislQ3tkMj22IuxBpvqiWqVFZL+cvF3SdL ur0bGhn7qFjouZrQNO0SP3eQP9E3dxRNyf3zyiuBzMvrejRFAt6V7oeIgKwjGns6fOBtQUonNQg sZQ0aauL4gW0OOpE4M5dDcWJo8GNLi1tkdvWc5+p8IzCTba898Lo16aluMogKJDOy6MZDBvb2pN 7SVgLij pk1wMheg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Fri, 22 Sep 2023 10:56:50 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777780407678874249 X-GMAIL-MSGID: 1777780407678874249 |
Series |
media: i2c: Annotate struct i2c_atr with __counted_by
|
|
Commit Message
Kees Cook
Sept. 22, 2023, 5:54 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 checking 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 i2c_atr.
[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
Cc: Wolfram Sang <wsa@kernel.org>
Cc: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Cc: Luca Ceresoli <luca.ceresoli@bootlin.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Tom Rix <trix@redhat.com>
Cc: linux-i2c@vger.kernel.org
Cc: llvm@lists.linux.dev
Signed-off-by: Kees Cook <keescook@chromium.org>
---
drivers/i2c/i2c-atr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Fri, Sep 22, 2023 at 10:54:25AM -0700, 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 checking 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 i2c_atr. > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci > > Cc: Wolfram Sang <wsa@kernel.org> > Cc: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > Cc: Luca Ceresoli <luca.ceresoli@bootlin.com> > Cc: Nathan Chancellor <nathan@kernel.org> > Cc: Nick Desaulniers <ndesaulniers@google.com> > Cc: Tom Rix <trix@redhat.com> > Cc: linux-i2c@vger.kernel.org > Cc: llvm@lists.linux.dev > Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Thanks -- Gustavo > --- > drivers/i2c/i2c-atr.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c > index 8ca1daadec93..f21475ae5921 100644 > --- a/drivers/i2c/i2c-atr.c > +++ b/drivers/i2c/i2c-atr.c > @@ -94,7 +94,7 @@ struct i2c_atr { > > struct notifier_block i2c_nb; > > - struct i2c_adapter *adapter[]; > + struct i2c_adapter *adapter[] __counted_by(max_adapters); > }; > > static struct i2c_atr_alias_pair * > -- > 2.34.1 > >
On Fri, Sep 22, 2023 at 10:54:25AM -0700, 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 checking 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 i2c_atr. > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci > > Cc: Wolfram Sang <wsa@kernel.org> > Cc: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > Cc: Luca Ceresoli <luca.ceresoli@bootlin.com> > Cc: Nathan Chancellor <nathan@kernel.org> > Cc: Nick Desaulniers <ndesaulniers@google.com> > Cc: Tom Rix <trix@redhat.com> > Cc: linux-i2c@vger.kernel.org > Cc: llvm@lists.linux.dev > Signed-off-by: Kees Cook <keescook@chromium.org> Removed "media: " from $subject and applied to for-next, thanks!
diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index 8ca1daadec93..f21475ae5921 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -94,7 +94,7 @@ struct i2c_atr { struct notifier_block i2c_nb; - struct i2c_adapter *adapter[]; + struct i2c_adapter *adapter[] __counted_by(max_adapters); }; static struct i2c_atr_alias_pair *