Message ID | 20231006201715.work.239-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 x8csp573795vqo; Fri, 6 Oct 2023 13:17:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhtaSG2XrB0bIEcacJRdQJ109NWXuYYo14raNhAj+W4k0qdU+K+rFAS5DbYuV/7Nybmd8k X-Received: by 2002:a05:6a21:3381:b0:16b:c20d:f97c with SMTP id yy1-20020a056a21338100b0016bc20df97cmr2670156pzb.0.1696623457700; Fri, 06 Oct 2023 13:17:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696623457; cv=none; d=google.com; s=arc-20160816; b=t3kCpKveQckXkFBGQrApMx4yDJTJexjXACBvtifxJkwyb0zn1IUefL+RZar2CNLF5Y HP7Cwaz342l4894o1dzM5NVbKzMWUeSvGYArEKSW0X924MyCKSsx49pvu4mj8JVa5DWz a5Y6nqfBscGyLJHep74wqzORbmad4jPFulZZX5I/pwePSm2PkHpuZBoxxJJ5Hn5iooVx yKREVZbN+rr8yIlJ7VQe+E3PRXO28uUnSxRI8kUHrLnx7+sRzOFBNdt2QOR7CGq/lP3n fkk+Lja7gs8VE9HWcWkMmAwxETw9oV7Gm2JmJqfBw3vhfiJXYHOTzNIt9+EpWEJ7TDu0 ZMgg== 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=pjnr6MIfdcujcCvyrDmadksDTc6dwprcRhGznzbOSQc=; fh=QoZqAQn02Inx9FhFg6hRGfr+nrwdc0n6T8YJXQcPllM=; b=SlrRIqSE1FK/Wbke6/jQJzPNr/Fso2ApKSP40qGMzhTVtFoOaV3gnyMHE8AFCkmsgl bkOI4fyXax3ibPWv9ZSZILTJkt/4dXo1A+wbh/hILs6VSxeVR2Vt3b19JcpsKOVj7OcT eJFlw4qHs5+qObtGGw6TrT4hhyPAv+tk36E7q/Fw67k4RHxGbqOo8u0L/mmde5pxORPT 0zsHfzwcCT31b43Patkp6WN2OZb28dylcu2/8pgHCo9oi/+skMrkXahmsNGP44uI8XbO XxgYAga2mwfFcR6JFdCnLQqFF4nWSnzb5sa3UqvDPCts4vfm4rYv4JSl5CnIE6EBwm6w nyaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Wu/6dDFX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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. [23.128.96.38]) by mx.google.com with ESMTPS id bk13-20020a056a02028d00b005859b1b34f7si4312723pgb.862.2023.10.06.13.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 13:17:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Wu/6dDFX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 CBE7B809FA4B; Fri, 6 Oct 2023 13:17:32 -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 S233427AbjJFURW (ORCPT <rfc822;ezelljr.billy@gmail.com> + 18 others); Fri, 6 Oct 2023 16:17:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233437AbjJFURU (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 6 Oct 2023 16:17:20 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78F6EBD for <linux-kernel@vger.kernel.org>; Fri, 6 Oct 2023 13:17:18 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-692779f583fso2077686b3a.0 for <linux-kernel@vger.kernel.org>; Fri, 06 Oct 2023 13:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696623438; x=1697228238; 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=pjnr6MIfdcujcCvyrDmadksDTc6dwprcRhGznzbOSQc=; b=Wu/6dDFXiktLOMH8+ROpJmA6IOMvxkZP8PTPmCP8rGOgTUdCsiCnErr0RtCEukIt7I TzpsIkjBDP69hgfVTjPRxRVGcfyP15Em0ddUvyUN+W8sQbp3QKZ7Rbt3iP2Z67BTzaqR MDdb1cvyeyh+1T0t8pJRpGfw9gGkEt715P9yQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696623438; x=1697228238; 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=pjnr6MIfdcujcCvyrDmadksDTc6dwprcRhGznzbOSQc=; b=Ac/KXEGHjOKHt0U99aWQg1HEQpiSFs7H7idC/2jM2cX49X0oeUCuoyJqHry+sxqQi5 6wpqnMicXlO5jnZYLPvJhwS4nokQ2Nd5UjACG11SZzFjx+AzgH/Co/si5BxviASFe68O m1XAoPVUuH6cJZZ+fp84sU0O+kYULWqKjdHPoTuVdDI4J+sVio/27NaHyWwJGy0FfPQ+ USiehsEgxy+2vhzI6WnG9frj1VgpFsk4YkzCa47pE7lAdJuBdbGt7HoS483Y7lMDx0AG ZqNO9In7KykPw+QpP9Ia85dPTgn5aWDLnU8tMNn0UUvghmO/GhRKCNGZiLlGfAQOshkV YJjw== X-Gm-Message-State: AOJu0YxEMRltQAMz6I9kMlPefcHM339XQanSPOuMu7Cm+sy+tNE4zQJS YjPlktDU77hTz+UyPBICB3ziY0VnsBBqS6HHqfI= X-Received: by 2002:a05:6a20:6a11:b0:15a:1817:c493 with SMTP id p17-20020a056a206a1100b0015a1817c493mr10463727pzk.39.1696623437921; Fri, 06 Oct 2023 13:17:17 -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 c9-20020aa78809000000b0068a13b0b300sm1951757pfo.11.2023.10.06.13.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 13:17:17 -0700 (PDT) From: Kees Cook <keescook@chromium.org> To: Ping-Ke Shih <pkshih@realtek.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: rtw89: coex: Annotate struct rtw89_btc_btf_set_slot_table with __counted_by Date: Fri, 6 Oct 2023 13:17:15 -0700 Message-Id: <20231006201715.work.239-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1321; i=keescook@chromium.org; h=from:subject:message-id; bh=eu6W7wXw5RTTiD60SAAgUrQDRZxpZuc1EvwMJ2JgTAI=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlIGtLFrvUk7TV+fsu3RoZBXUeAY5BE45UBpI5o H04FXBoP4qJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZSBrSwAKCRCJcvTf3G3A JkN9D/9DbkQ9s24VTWKihPeasIWSlCASR9Q6UgMN2sh4QmgFMoBiZlxb12IObvOXPnLVlYdHbmX EVy9OcIWuPk43HGC3iU/j44eEHlpM/TqUYFwvguvhr8W3ZvbTF8lzfpmCs0SmJXhbFMBaZ5+mB2 2qIy4G6fMNcmwLK4jH/1l5P8/Ls4R6xkfMqkDb4ibaFLM+VlsWnSEQYN7HIWR5ZiT8vPIHPAymc 6mi+AVnfzirQ380CiVqi7z4Llsn8ZXvpBa7RbJc+XMfQlLESPt2LTk6gskIP+d/mAzribY7z7xF UJr/yeImzGyEY+MrWTNG64p3AhBR3uTee3rMN+6QU/hQu8A9ng7ddLD+J/uVZYdOdMXqpHIQD0T sKVockWMg/GUEvNzpsNb6ebVslSZXGRRCN7NKF8y7T3jNQKzxDO0dppZdThl+D9gjUNeILx4rqs UWb00OkZQK2gTdUSzsm3Qy9fwl0/nCa7nwaIT86096mOrdJx+kkV23p4fujH9DXzzzuKJIrZ63h 2aXKuHw1/zaTlGRFHj0yAW1UVA487R9UVz+H/dDgCooswodM7cvImtDGZvKogqwPG2ICG7pepP2 V75uq6CUWbyaJRKJxrdFTlZLJtnlcmkqDtyNWUN7zOI8kEGoDOLH5Ab4a73LxseCO2tTiBtgstk FLmAlOo dZguPuXA== 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:32 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779038638341676846 X-GMAIL-MSGID: 1779038638341676846 |
Series |
wifi: rtw89: coex: Annotate struct rtw89_btc_btf_set_slot_table 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
rtw89_btc_btf_set_slot_table.
Cc: Ping-Ke Shih <pkshih@realtek.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/realtek/rtw89/coex.c | 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 > rtw89_btc_btf_set_slot_table. > > Cc: Ping-Ke Shih <pkshih@realtek.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!
On Fri, 2023-10-06 at 13:17 -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 > rtw89_btc_btf_set_slot_table. > > Cc: Ping-Ke Shih <pkshih@realtek.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/realtek/rtw89/coex.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c > index 4ba8b3df70ae..d66a1152c3f5 100644 > --- a/drivers/net/wireless/realtek/rtw89/coex.c > +++ b/drivers/net/wireless/realtek/rtw89/coex.c > @@ -237,7 +237,7 @@ struct rtw89_btc_btf_set_report { > struct rtw89_btc_btf_set_slot_table { > u8 fver; > u8 tbl_num; > - u8 buf[]; > + u8 buf[] __counted_by(tbl_num); This struct isn't defined properly. It should be struct rtw89_btc_btf_set_slot_table { u8 fver; u8 tbl_num; struct rtw89_btc_fbtc_slot tbl[] __counted_by(tbl_num); } __packed; And, we should modify rtw89_btc_fw_set_slots() as well. Another struct 'rtw89_btc_btf_set_mon_reg' has similar problem. So, NACK this patch. I will prepare one or two patches for them next week. By the way, I have question about __counted_by(). Can I apply it to little/big- endian 'num'? Like struct foo { ... __le32 num; __le32 data[] __counted_by(num); } > } __packed; > > struct rtw89_btc_btf_set_mon_reg { > -- > 2.34.1 >
On Sat, Oct 07, 2023 at 01:20:43AM +0000, Ping-Ke Shih wrote: > On Fri, 2023-10-06 at 13:17 -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 > > rtw89_btc_btf_set_slot_table. > > > > Cc: Ping-Ke Shih <pkshih@realtek.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/realtek/rtw89/coex.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c > > index 4ba8b3df70ae..d66a1152c3f5 100644 > > --- a/drivers/net/wireless/realtek/rtw89/coex.c > > +++ b/drivers/net/wireless/realtek/rtw89/coex.c > > @@ -237,7 +237,7 @@ struct rtw89_btc_btf_set_report { > > struct rtw89_btc_btf_set_slot_table { > > u8 fver; > > u8 tbl_num; > > - u8 buf[]; > > + u8 buf[] __counted_by(tbl_num); > > This struct isn't defined properly. It should be > > struct rtw89_btc_btf_set_slot_table { > u8 fver; > u8 tbl_num; > struct rtw89_btc_fbtc_slot tbl[] __counted_by(tbl_num); > } __packed; > > And, we should modify rtw89_btc_fw_set_slots() as well. > > Another struct 'rtw89_btc_btf_set_mon_reg' has similar problem. > > So, NACK this patch. I will prepare one or two patches for them next week. Ah-ha; thank you! > By the way, I have question about __counted_by(). Can I apply it to little/big- > endian 'num'? Like > > struct foo { > ... > __le32 num; > __le32 data[] __counted_by(num); > } Unfortunately not yet. I hope to see it extended in the future to allow for arbitrary expressions. For this first step, it only handles native sizes.
Hi Kees, > -----Original Message----- > From: Kees Cook <keescook@chromium.org> > Sent: Tuesday, October 10, 2023 12:56 AM > To: Ping-Ke Shih <pkshih@realtek.com> > Cc: kvalo@kernel.org; llvm@lists.linux.dev; linux-kernel@vger.kernel.org; linux-wireless@vger.kernel.org; > linux-hardening@vger.kernel.org; trix@redhat.com; nathan@kernel.org; ndesaulniers@google.com; > gustavoars@kernel.org > Subject: Re: [PATCH] wifi: rtw89: coex: Annotate struct rtw89_btc_btf_set_slot_table with __counted_by > > On Sat, Oct 07, 2023 at 01:20:43AM +0000, Ping-Ke Shih wrote: > > On Fri, 2023-10-06 at 13:17 -0700, Kees Cook wrote: > > > > So, NACK this patch. I will prepare one or two patches for them next week. > > Ah-ha; thank you! I have sent two patches [1]. Please help to review and Cc people if needed. [1] https://lore.kernel.org/linux-wireless/20231011063725.25276-1-pkshih@realtek.com/T/#t
diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c index 4ba8b3df70ae..d66a1152c3f5 100644 --- a/drivers/net/wireless/realtek/rtw89/coex.c +++ b/drivers/net/wireless/realtek/rtw89/coex.c @@ -237,7 +237,7 @@ struct rtw89_btc_btf_set_report { struct rtw89_btc_btf_set_slot_table { u8 fver; u8 tbl_num; - u8 buf[]; + u8 buf[] __counted_by(tbl_num); } __packed; struct rtw89_btc_btf_set_mon_reg {