Message ID | ZBSjx236+BTiRByf@work |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp479269wrt; Fri, 17 Mar 2023 10:56:01 -0700 (PDT) X-Google-Smtp-Source: AK7set8FBiUpGlFs/5DExrm00jTStPfmOaEu3YF4yHzDyUYWXnbCGBjzh4wvYC42DiZ9AalMW30U X-Received: by 2002:a17:902:728c:b0:1a0:563e:b0c4 with SMTP id d12-20020a170902728c00b001a0563eb0c4mr8151852pll.2.1679075761497; Fri, 17 Mar 2023 10:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679075761; cv=none; d=google.com; s=arc-20160816; b=KOUQgUlPz06XXeUQn6wi7MjpagNW/HWW/n1M6gDZiuLJmLQ01UBnGauHH12Kr2Xv6i AByMyfHW4VVYq967es6GOwl3XULYVBP7fVI59nfAoFbIArKA2EpoznzCJ4h2Xyr4ejRv N5Pi0V6iJdh2YaPjEyvOOr4TdPoPEIBiaZjHjLEmLmnWgrcTtFlsZXAYoukeERUrX9N1 k6x5f14FOvkZH3u9udKxStI+SwDIc6DfX2Sz+PumxM10B5rkzbYjQVfLwHDiJicRVVmx KEVMLrEW+YP4lGTDEijzSyA44bdUu1n5rQ3bi7ONN4afzBORYqUnyo/iA979Jzk7WYSe 80dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=/TCgzdDeqPTn4MLTm87rOSnZigsTuyDmuZzd3cAXllc=; b=QXI/3PgtgvzVrXUo1MpY0R7wQbqqryvoSW23c3GvUFlP/mOYvkO7w497zhNgQeNtU4 XKbVY4Mu5+uK4C/QAr6BtNExoC8whbdr3NPivw38iKaMUPr+l5DKhGiLtNqiSM1qDVNa X23RC0eCBaJ8mGn2iec8L/WWahv4y/zH99wBWYU0pMRo1llFgXyTQ9SMbJstOgA3aMFL jRxzS1VhKfkR6H23pBIPejSlTXTbrN8zf0XC+QCuaVk9+HnXnT+T1MHo1+x4Bh4X5PDS /wT3SzynArR/L/MqlSeDQ554W7sLnAy6PvCXsQTBxBuanhN9ts6pWbjb9smNnJroU2UQ nZzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FLwyozEt; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o9-20020a170902d4c900b0019ab69570aasi674129plg.417.2023.03.17.10.55.45; Fri, 17 Mar 2023 10:56:01 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=FLwyozEt; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229585AbjCQRaX (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Fri, 17 Mar 2023 13:30:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbjCQRaV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 17 Mar 2023 13:30:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 266CA2ED6F; Fri, 17 Mar 2023 10:30:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DFFCEB82641; Fri, 17 Mar 2023 17:30:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77C30C433EF; Fri, 17 Mar 2023 17:30:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679074217; bh=l/oo++nd5/THbGDXNgQewvPeaT962pxyBBxTkzCqAOQ=; h=Date:From:To:Cc:Subject:From; b=FLwyozEt5oRVYycYB4oitlmYDsjagBORL5pRLaZ+bE5FH9+YFohf9QIrr+NEL4vRW fBYfzRBidm6cu/rRAVgBEpfz3NUEMy7Re+jIo8lGvZoZQmAiDnR1oE81bk3iid78GW 2ZWT0Gxb13uckPWDFazaxHbeOwfcbyzPuiJh9PycqmOEnc4Nqxl2BHANRUS8tMMOkw Y1G9W9LTxsIcjoDGqkV2L7HNkv5NRnS6aAIhyZqmziiGjK+91im20MFRQtWT140Tc+ 3A9gj10k7B6YBpizqgs63JdlIfXk8+BRTTaMKYTBH8vtw3UtjlMoC1MDKH7uhXfIcr NZMSsbxKvgppA== Date: Fri, 17 Mar 2023 11:30:47 -0600 From: "Gustavo A. R. Silva" <gustavoars@kernel.org> To: Christian Lamparter <chunkeey@googlemail.com>, Kalle Valo <kvalo@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" <gustavoars@kernel.org>, linux-hardening@vger.kernel.org Subject: [PATCH][next] carl9170: Fix multiple -Warray-bounds warnings Message-ID: <ZBSjx236+BTiRByf@work> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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?1760638545844117054?= X-GMAIL-MSGID: =?utf-8?q?1760638545844117054?= |
Series |
[next] carl9170: Fix multiple -Warray-bounds warnings
|
|
Commit Message
Gustavo A. R. Silva
March 17, 2023, 5:30 p.m. UTC
GCC (and Clang)[1] does not like having a partially allocated object,
since it cannot reason about it for bounds checking. Instead, fully
allocate struct carl9170_cmd.
Fix the following warnings Seen under GCC 13:
drivers/net/wireless/ath/carl9170/cmd.c:125:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[4]’ [-Warray-bounds=]
drivers/net/wireless/ath/carl9170/cmd.c:126:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[4]’ [-Warray-bounds=]
drivers/net/wireless/ath/carl9170/cmd.c:125:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=]
drivers/net/wireless/ath/carl9170/cmd.c:126:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=]
drivers/net/wireless/ath/carl9170/cmd.c:161:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=]
drivers/net/wireless/ath/carl9170/cmd.c:162:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=]
drivers/net/wireless/ath/carl9170/cmd.c:163:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=]
drivers/net/wireless/ath/carl9170/cmd.c:164:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=]
drivers/net/wireless/ath/carl9170/cmd.c:125:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[8]’ [-Warray-bounds=]
drivers/net/wireless/ath/carl9170/cmd.c:126:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[8]’ [-Warray-bounds=]
drivers/net/wireless/ath/carl9170/cmd.c:220:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[8]’ [-Warray-bounds=]
Link: https://github.com/KSPP/linux/issues/268
Link: godbolt.org/z/KP97sxh3T [1]
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/net/wireless/ath/carl9170/cmd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 3/17/23 18:30, Gustavo A. R. Silva wrote: > GCC (and Clang)[1] does not like having a partially allocated object, > since it cannot reason about it for bounds checking. Instead, fully > allocate struct carl9170_cmd. > > Fix the following warnings Seen under GCC 13: > drivers/net/wireless/ath/carl9170/cmd.c:125:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[4]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:126:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[4]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:125:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:126:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:161:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:162:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:163:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:164:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:125:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[8]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:126:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[8]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:220:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[8]’ [-Warray-bounds=] > > Link: https://github.com/KSPP/linux/issues/268 > Link: godbolt.org/z/KP97sxh3T [1] > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Acked-by: Christian Lamparter <chunkeey@gmail.com> > --- > drivers/net/wireless/ath/carl9170/cmd.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/wireless/ath/carl9170/cmd.c b/drivers/net/wireless/ath/carl9170/cmd.c > index f2b4f537e4c1..b8ed193c0195 100644 > --- a/drivers/net/wireless/ath/carl9170/cmd.c > +++ b/drivers/net/wireless/ath/carl9170/cmd.c > @@ -120,7 +120,7 @@ struct carl9170_cmd *carl9170_cmd_buf(struct ar9170 *ar, > { > struct carl9170_cmd *tmp; > > - tmp = kzalloc(sizeof(struct carl9170_cmd_head) + len, GFP_ATOMIC); > + tmp = kzalloc(sizeof(*tmp), GFP_ATOMIC); This might throw-off people here. The reason this works is because carl9170_cmd struct looks like this: | |struct carl9170_cmd { | struct carl9170_cmd_head hdr; <-- 4 bytes | union { | struct carl9170_set_key_cmd setkey; | [...] | struct carl9170_rx_filter_cmd rx_filter; | u8 data[CARL9170_MAX_CMD_PAYLOAD_LEN]; <---- that's 60 bytes | } __packed __aligned(4); |} __packed __aligned(4); All commands have to fit into the command endpoint max size which is 64 bytes.
On Fri, Mar 17, 2023 at 11:30:47AM -0600, Gustavo A. R. Silva wrote: > GCC (and Clang)[1] does not like having a partially allocated object, > since it cannot reason about it for bounds checking. Instead, fully > allocate struct carl9170_cmd. > > Fix the following warnings Seen under GCC 13: > drivers/net/wireless/ath/carl9170/cmd.c:125:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[4]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:126:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[4]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:125:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:126:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:161:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:162:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:163:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:164:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:125:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[8]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:126:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[8]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:220:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[8]’ [-Warray-bounds=] > > Link: https://github.com/KSPP/linux/issues/268 > Link: godbolt.org/z/KP97sxh3T [1] > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org>
"Gustavo A. R. Silva" <gustavoars@kernel.org> wrote: > GCC (and Clang)[1] does not like having a partially allocated object, > since it cannot reason about it for bounds checking. Instead, fully > allocate struct carl9170_cmd. > > Fix the following warnings Seen under GCC 13: > drivers/net/wireless/ath/carl9170/cmd.c:125:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[4]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:126:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[4]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:125:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:126:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:161:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:162:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:163:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:164:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:125:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[8]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:126:30: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[8]’ [-Warray-bounds=] > drivers/net/wireless/ath/carl9170/cmd.c:220:12: warning: array subscript ‘struct carl9170_cmd[0]’ is partly outside array bounds of ‘unsigned char[8]’ [-Warray-bounds=] > > Link: https://github.com/KSPP/linux/issues/268 > Link: godbolt.org/z/KP97sxh3T [1] > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > Acked-by: Christian Lamparter <chunkeey@gmail.com> > Reviewed-by: Kees Cook <keescook@chromium.org> > Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com> Patch applied to ath-next branch of ath.git, thanks. 72383ed78c1c wifi: carl9170: Fix multiple -Warray-bounds warnings
diff --git a/drivers/net/wireless/ath/carl9170/cmd.c b/drivers/net/wireless/ath/carl9170/cmd.c index f2b4f537e4c1..b8ed193c0195 100644 --- a/drivers/net/wireless/ath/carl9170/cmd.c +++ b/drivers/net/wireless/ath/carl9170/cmd.c @@ -120,7 +120,7 @@ struct carl9170_cmd *carl9170_cmd_buf(struct ar9170 *ar, { struct carl9170_cmd *tmp; - tmp = kzalloc(sizeof(struct carl9170_cmd_head) + len, GFP_ATOMIC); + tmp = kzalloc(sizeof(*tmp), GFP_ATOMIC); if (tmp) { tmp->hdr.cmd = cmd; tmp->hdr.len = len;