Message ID | 20231003232852.work.257-kees@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp2413232vqb; Tue, 3 Oct 2023 16:29:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHLt1t+kNtlB5gKPPGjhFQBkFAs5D90VtXcNM/hU8bWQWsuap9cyf6hy1VaMnLITYB6BMJ0 X-Received: by 2002:a17:90b:fcb:b0:276:6b9d:7503 with SMTP id gd11-20020a17090b0fcb00b002766b9d7503mr762116pjb.28.1696375759310; Tue, 03 Oct 2023 16:29:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696375759; cv=none; d=google.com; s=arc-20160816; b=nM5Y8iNHB50g4qW8Msj8evE4nD5+loUKdxneIZYm1bpuBphZ7ubdi6PHoutHNMsPac TJhlRZbFIWYRIsYJIQ/PoH7aak1HukX8YU4LErLEZuy3E6ndj9Lc2fDwpWkOlWehVic7 YH/o3GHdmUC04xIHoQaPjWq2yNf+ZIv43KJ3lC+l1aJoHaHRS3V2V1taoqrssFMWcECb hozXRrlu85pSdPfsjOJy5R3PTxEv/O5Hd0liZ9HbN+lPZkK1aCCHyCetO6xfw6yEiStI iv6kJfIKUVBjekXXOxTAZpaOnrJRKLW9ggsLHOJAQ6cN2cywVxM+UTpGgi8mI9Alc7Di r2xg== 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=mewr2b70zj+E+PpMtuqRQXYpLvw4Y2kPAtz8L71vU0I=; fh=3DHpF4sDZlyMK9g57EQ8GbCzmPx96QFtHW/C3mIWFnw=; b=M2/iyU8qRxHe/6KpfuD1jWjPmrbmavpYq6h91iq21wmxtnWGDshgbmnQutC2DMST1f cgy9xJP3Jl0K2sEWJzag1m8VStMr7UIpWkLDJjfu1amZox3TaBTO++cbHnkF02iitdL7 CGHCWsiZz48ypYqubVY9F40+blxRqzyO3zO8ADBAWkdgkE+7UedF5UAtEl0oOUKPTcg9 mmUjAxsMRLpNQbVOGtbcG5FYIwzmXRViNrTPNme1kez2+Nh8WF88bhaFus+ScjXCfA0g jwkFk/Adi9ZYheBV4OwmrG3exn9oHZKg3TLJ2fB1hONAlcFcINFw3WmXo6pAhkBz7c1B Ax+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Gq+gphMw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id p5-20020a17090a74c500b00263eb5054fdsi297226pjl.32.2023.10.03.16.29.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:29:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Gq+gphMw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 3EE888186539; Tue, 3 Oct 2023 16:29:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235508AbjJCX3C (ORCPT <rfc822;chrisfriedt@gmail.com> + 17 others); Tue, 3 Oct 2023 19:29:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbjJCX3B (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 3 Oct 2023 19:29:01 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66AA7B4 for <linux-kernel@vger.kernel.org>; Tue, 3 Oct 2023 16:28:57 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1c62d61dc96so10932355ad.0 for <linux-kernel@vger.kernel.org>; Tue, 03 Oct 2023 16:28:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696375737; x=1696980537; 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=mewr2b70zj+E+PpMtuqRQXYpLvw4Y2kPAtz8L71vU0I=; b=Gq+gphMwlzljnJCKit7St6eAm1T3gh4oMGIP2fokDe9rOonYZfG2soLJwkTfm8Eo9h rfljuBIeizdZtNbUbOXnc9m7VkIleh3hhJG+jcsBmg+ZJbwea4IW5wcRxsTBxncRWQ2L 7MV7Bwh+SJqxK0Ida1JGynx2Z86cK2sM4Q9zk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696375737; x=1696980537; 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=mewr2b70zj+E+PpMtuqRQXYpLvw4Y2kPAtz8L71vU0I=; b=hxSxAYCtRYwE5CNPbCHC6yL6eqXCOEYcDe38W+f/JmEn27jVOFepS8s9Fcc63SVs34 AedSVGk8O3GpFKooppc8igNBPblexEEBBo90kx6eIplCu6SBgvZnHR0TwhyHqVBahuFp Hg88D7XlXs8+bNnAwviH9tqw173eV+UYau76wjuPbG7YDY8sTz2l2U3EKnPUpYKj0KJ4 hqhAubkAVnKafYzoeVIt4NmuUhBDguVGN4TWV6SuFZHxpx/WsnVA9ahaNSV1SKQg2XAQ 9AukmVyjCvAI5u6kq/akaPjWeE8VlIjj6WINnwyd3txohZEFzyDnlSqfgPvC31oxv4eF YOsg== X-Gm-Message-State: AOJu0Yx7/D56pDHw37YXurqqA0UNp4TUBZLRLLkJYIua4PgNZqIgANtQ 7PE9r8bjATYVu2M1DexRqL/o+g== X-Received: by 2002:a17:903:24c:b0:1c7:4f87:3dbe with SMTP id j12-20020a170903024c00b001c74f873dbemr1177087plh.31.1696375736870; Tue, 03 Oct 2023 16:28:56 -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 s16-20020a170902ea1000b001bbd1562e75sm2201487plg.55.2023.10.03.16.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:28:56 -0700 (PDT) From: Kees Cook <keescook@chromium.org> To: Liam Girdwood <lgirdwood@gmail.com> Cc: Kees Cook <keescook@chromium.org>, Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>, "Gustavo A. R. Silva" <gustavoars@kernel.org>, alsa-devel@alsa-project.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] ASoC: soc-dapm: Annotate struct snd_soc_dapm_widget_list with __counted_by Date: Tue, 3 Oct 2023 16:28:53 -0700 Message-Id: <20231003232852.work.257-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2049; i=keescook@chromium.org; h=from:subject:message-id; bh=6X+YStEd0LKlaV0dQ/+jU63am+Tg/LnFddxaxahC+bw=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlHKO1gHu4l9h8ToOMvkOmkto8cSVU/vIIIfRBe GeN6y35pSWJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRyjtQAKCRCJcvTf3G3A JgNjD/4q5gV6j+9dUNB2OWkREBYsVc6X++ugjnovyEuKGMIO5OVnXc9jH79Kp+y27z4flA8uzzb +/r402rgPMkNPLC5GCQr12BvpEC1X8LALA79ist2DeSe1oktOoVS3aMe+/Xy6TqdcMeDeIZoo/7 T1Rn6zkPYXU/8vtFSebH5zH51EeajceKubb+yEJ8rmen79X1C7Gyeb7Ijc3HWazoUS0FKasUx5A cOnmPn+ui24LfU1Qa7V7TdcR9rfRZ8updCADmqZ6QM5DHxxwuvgir/CGTN4izQGV1OUxMJgJS4l +wodJb5c0SRHeF+7+yAT6WO4qsuBQQwFXdnsw2ywzFe2rTOZ22M/mAcK22lbc28oAaVPrL6tWj1 MT6VpE1AqFevzjlgTxDde83nlltZhG2Vveh6cPfzFBtn53tVWK1kaPFTw5cr4Ku6TnJswmeRLtJ sxEuDhD/KSvpRx1PhGEU8jGsnOjuSnT9E79xugfNmv/2wjEIJSha6UeyebKRB3HpoAqL5eXJBDb 37rBp22xYP5M/W7HQmIFzZ+iR3s7UV+UW+3JYpQusIFADZzQH0yUHk/DoV7EVgBxMtYXwAs0xOn vxcomU0K+gw5b+cB6mxXslxsu7jQ5DVxyatycmhvSOz7GUbXtQlraWBOe+LhgFI/Y8J7Mupz2q9 aPyj3M0 Mg5yrwWA== 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Tue, 03 Oct 2023 16:29:16 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778778908061985029 X-GMAIL-MSGID: 1778778908061985029 |
Series |
ASoC: soc-dapm: Annotate struct snd_soc_dapm_widget_list with __counted_by
|
|
Commit Message
Kees Cook
Oct. 3, 2023, 11:28 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 snd_soc_dapm_widget_list.
Additionally, since the element count member must be set before accessing
the annotated flexible array member, move its initialization earlier.
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: alsa-devel@alsa-project.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>
---
include/sound/soc-dapm.h | 2 +-
sound/soc/soc-dapm.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
Comments
On 10/4/23 01:28, 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 snd_soc_dapm_widget_list. > Additionally, since the element count member must be set before accessing > the annotated flexible array member, move its initialization earlier. > > Cc: Liam Girdwood <lgirdwood@gmail.com> > Cc: Mark Brown <broonie@kernel.org> > Cc: Jaroslav Kysela <perex@perex.cz> > Cc: Takashi Iwai <tiwai@suse.com> > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> > Cc: alsa-devel@alsa-project.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 -- Gustavo > --- > include/sound/soc-dapm.h | 2 +- > sound/soc/soc-dapm.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h > index d2faec9a323e..51516c93916e 100644 > --- a/include/sound/soc-dapm.h > +++ b/include/sound/soc-dapm.h > @@ -717,7 +717,7 @@ struct snd_soc_dapm_context { > /* A list of widgets associated with an object, typically a snd_kcontrol */ > struct snd_soc_dapm_widget_list { > int num_widgets; > - struct snd_soc_dapm_widget *widgets[]; > + struct snd_soc_dapm_widget *widgets[] __counted_by(num_widgets); > }; > > #define for_each_dapm_widgets(list, i, widget) \ > diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c > index 2512aadf95f7..2e3df47c9cf3 100644 > --- a/sound/soc/soc-dapm.c > +++ b/sound/soc/soc-dapm.c > @@ -497,8 +497,8 @@ static int dapm_kcontrol_add_widget(struct snd_kcontrol *kcontrol, > if (!new_wlist) > return -ENOMEM; > > - new_wlist->widgets[n - 1] = widget; > new_wlist->num_widgets = n; > + new_wlist->widgets[n - 1] = widget; > > data->wlist = new_wlist; >
On Tue, 03 Oct 2023 16:28:53 -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 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 snd_soc_dapm_widget_list. > Additionally, since the element count member must be set before accessing > the annotated flexible array member, move its initialization earlier. > > [...] Applied to https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next Thanks! [1/1] ASoC: soc-dapm: Annotate struct snd_soc_dapm_widget_list with __counted_by commit: 80e698e2df5ba2124bdeca37f1e589de58a4d514 All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index d2faec9a323e..51516c93916e 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h @@ -717,7 +717,7 @@ struct snd_soc_dapm_context { /* A list of widgets associated with an object, typically a snd_kcontrol */ struct snd_soc_dapm_widget_list { int num_widgets; - struct snd_soc_dapm_widget *widgets[]; + struct snd_soc_dapm_widget *widgets[] __counted_by(num_widgets); }; #define for_each_dapm_widgets(list, i, widget) \ diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 2512aadf95f7..2e3df47c9cf3 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -497,8 +497,8 @@ static int dapm_kcontrol_add_widget(struct snd_kcontrol *kcontrol, if (!new_wlist) return -ENOMEM; - new_wlist->widgets[n - 1] = widget; new_wlist->num_widgets = n; + new_wlist->widgets[n - 1] = widget; data->wlist = new_wlist;