Message ID | 20230513114938.179085-1-krzysztof.kozlowski@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5742542vqo; Sat, 13 May 2023 05:35:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5CgkQgvRtMwAASvu9gZuqd6jw5wmsbhQg035CZ/cabPPUEzNlIJ5uwNwv+OwFC7nvp+ATG X-Received: by 2002:a05:6a20:3d1a:b0:104:d028:ffe8 with SMTP id y26-20020a056a203d1a00b00104d028ffe8mr4732298pzi.45.1683981307582; Sat, 13 May 2023 05:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683981307; cv=none; d=google.com; s=arc-20160816; b=soXyUI7B7ACUA3FQ+WBGf8xLwEIQcDlVwQ4JOovAr2whWAT5kN5kVHT784G/K2GPPJ rUTY8IFca/sAw7Uv7Qm+sw/biLDSfS7FZeyuJ8zec8a4xdwQ+WM7mMGxR1br8UGxtV5k K2sc60H7XXn5q8XQZzPYWo8kufeJbrRseT2I0Dsly9YOIPoLEQPkz1nEjp4Wuzxcw4mZ 7HKb6OY3BvjSsUiXZpefb9bIDIW43YD6WMMQsoNzpQJQGoxuZ//IWEcX6rcff4l5K8gF SGoRydHLkwX9tgbhOrKvGfglF4DtyNgaA01Zp6wXSFZLVnuOENvtltqpkH1TsQGSVoY3 2X4A== 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:to:from:dkim-signature; bh=ZiSbSUosuiUZqcS7c/GQgLfHatjAKKg2yNJfrvJFGcQ=; b=GTAvYUJlZ2a4YyzN31WFaPqUrk+lINwBTD7hsGIpG/X6+yzDJENMRZQxSANg7K7Jf1 BmwSg3g+s5KLy8LpDprQPqsDAqQBwpcADiLYiOkUJJ6hSjw5lHJX8s5BHT/02YwQQfS+ TvMigaqPo2j9rZIZeeELn2PmHEN/ICNBw3NALIYtWypuiN4Cj+XptBL82k4bj0PRlsdv UDtpA/vEp+s4eBkuoSjrLnWcFgFK0D4L07KUAXfmVQ5Vfp2Dnjg0gxZzprDqR/rTgxDy dqiUpiyVoIvZf2gQAhC7ExJnupStlk/I2bDBtIJ6X+bwX1qNXm4Fh62pj4kFEg1bItQf AuOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B5dZsgqC; 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=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f18-20020a637552000000b0053071bc497dsi7167506pgn.90.2023.05.13.05.34.20; Sat, 13 May 2023 05:35:07 -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=@linaro.org header.s=google header.b=B5dZsgqC; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236812AbjEMLtr (ORCPT <rfc822;peekingduck44@gmail.com> + 99 others); Sat, 13 May 2023 07:49:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230205AbjEMLtp (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 13 May 2023 07:49:45 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D40C10D5 for <linux-kernel@vger.kernel.org>; Sat, 13 May 2023 04:49:43 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-50bd37ca954so97101915a12.0 for <linux-kernel@vger.kernel.org>; Sat, 13 May 2023 04:49:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683978580; x=1686570580; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=ZiSbSUosuiUZqcS7c/GQgLfHatjAKKg2yNJfrvJFGcQ=; b=B5dZsgqCdQYJvBqGfHIpCDUvgxGam71ot87mOSUr0/tfzT8jM+bIz3yHlLZQY2wgkV cYJD8PUSpUNYvyU3wbVDQXwNpYD0qpFpPROmKsYihdBwcq5wZoI0bfhN8sttQeXefp+n z5UMK9Z/0N+Yn+awIDU/yqNDDTEaWBi9I2htvUbZ9WOGCQ2E8tPp/V9adn6ZoKvzm8e2 mxGtlsssxprUOn1cBiTCnLhg5ALVRfw/+O1u1ac8dMYyxIkhf+nIgD/UNmyvmXgR1u5w BVW6LWUOHdiUu/OdTezHqhdVTc6wtQvr5EmgwWE6njl4+eXAdw/Bl16njMkBmon3RYYc 4RWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683978580; x=1686570580; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZiSbSUosuiUZqcS7c/GQgLfHatjAKKg2yNJfrvJFGcQ=; b=HD2NmNmJmeS7juHQgVySwnoDXWz8TRw8XXhZEMIUWmt1Jjg3i3dv2jbyGtGqjODNTb XieQUinXZQRLija3LyMqNrmpTNYu9kWD2uclrx5IPtDAUMJ6ZjEjO9ocaSwkFgryl/vR /a5QS8ld2I/bIaXaZWoPBoN4OhLhG7RSgWBGF+mWBFg9mVKUUFRB9MXUbRBJgA10/nkC DkFnA1cO8T1s4Bj5PK2h/kD1kYCGXg172yCIT0BgYladJ6dieWuReneyD2jdqdbVf+Ie qnTZrXwvCYnCnlOD29r2TsW6XzaLP15XOBdBjpfXDbgLBpJGJcmgbz49Z4/spGJZq4y3 +leQ== X-Gm-Message-State: AC+VfDynzwi9snjk1Uvh61C6B5Ao3hQQkPC+zPlQeK6lSMj+y6VmLqsD XJnVbmAFuXF7VPBK4wO2TQoUgg== X-Received: by 2002:a50:ee0c:0:b0:50b:c56c:43d0 with SMTP id g12-20020a50ee0c000000b0050bc56c43d0mr25205160eds.1.1683978580503; Sat, 13 May 2023 04:49:40 -0700 (PDT) Received: from krzk-bin.. ([2a02:810d:15c0:828:a3aa:fd4:f432:676b]) by smtp.gmail.com with ESMTPSA id n25-20020a056402061900b0050a276e7ba8sm5030638edv.36.2023.05.13.04.49.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 May 2023 04:49:39 -0700 (PDT) From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> To: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Samuel Ortiz <sameo@linux.intel.com>, Thierry Escande <thierry.escande@collabora.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] nfx: llcp: fix possible use of uninitialized variable in nfc_llcp_send_connect() Date: Sat, 13 May 2023 13:49:38 +0200 Message-Id: <20230513114938.179085-1-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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?1765782383679877022?= X-GMAIL-MSGID: =?utf-8?q?1765782383916523374?= |
Series |
nfx: llcp: fix possible use of uninitialized variable in nfc_llcp_send_connect()
|
|
Commit Message
Krzysztof Kozlowski
May 13, 2023, 11:49 a.m. UTC
If sock->service_name is NULL, the local variable
service_name_tlv_length will not be assigned by nfc_llcp_build_tlv(),
later leading to using value frmo the stack. Smatch warning:
net/nfc/llcp_commands.c:442 nfc_llcp_send_connect() error: uninitialized symbol 'service_name_tlv_length'.
Fixes: de9e5aeb4f40 ("NFC: llcp: Fix usage of llcp_add_tlv()")
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
net/nfc/llcp_commands.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Sat, May 13, 2023 at 01:51:12PM +0200, Krzysztof Kozlowski wrote: > On 13/05/2023 13:49, Krzysztof Kozlowski wrote: > > If sock->service_name is NULL, the local variable > > service_name_tlv_length will not be assigned by nfc_llcp_build_tlv(), > > later leading to using value frmo the stack. Smatch warning: > > > > net/nfc/llcp_commands.c:442 nfc_llcp_send_connect() error: uninitialized symbol 'service_name_tlv_length'. > > Eh, typo in subject prefix. V2 in shortly... Also, s/frmo/from/ And please consider moving local variables towards reverse xmas tree - longest line to shortest - order for networking code.
On Sat, May 13, 2023 at 01:49:38PM +0200, Krzysztof Kozlowski wrote: > If sock->service_name is NULL, the local variable > service_name_tlv_length will not be assigned by nfc_llcp_build_tlv(), > later leading to using value frmo the stack. Smatch warning: > > net/nfc/llcp_commands.c:442 nfc_llcp_send_connect() error: uninitialized symbol 'service_name_tlv_length'. > > Fixes: de9e5aeb4f40 ("NFC: llcp: Fix usage of llcp_add_tlv()") > Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> > --- > net/nfc/llcp_commands.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/net/nfc/llcp_commands.c b/net/nfc/llcp_commands.c > index 41e3a20c8935..cdb001de0692 100644 > --- a/net/nfc/llcp_commands.c > +++ b/net/nfc/llcp_commands.c > @@ -390,7 +390,8 @@ int nfc_llcp_send_connect(struct nfc_llcp_sock *sock) > const u8 *service_name_tlv = NULL; > const u8 *miux_tlv = NULL; > const u8 *rw_tlv = NULL; > - u8 service_name_tlv_length, miux_tlv_length, rw_tlv_length, rw; > + u8 service_name_tlv_length = 0; > + u8 miux_tlv_length, rw_tlv_length, rw; While moving this around, can reduce the number of spaces before rw_tlv_length? > int err; > u16 size = 0; > __be16 miux; > -- > 2.34.1 > >
On 14/05/2023 10:29, Simon Horman wrote: > On Sat, May 13, 2023 at 01:51:12PM +0200, Krzysztof Kozlowski wrote: >> On 13/05/2023 13:49, Krzysztof Kozlowski wrote: >>> If sock->service_name is NULL, the local variable >>> service_name_tlv_length will not be assigned by nfc_llcp_build_tlv(), >>> later leading to using value frmo the stack. Smatch warning: >>> >>> net/nfc/llcp_commands.c:442 nfc_llcp_send_connect() error: uninitialized symbol 'service_name_tlv_length'. >> >> Eh, typo in subject prefix. V2 in shortly... > > Also, s/frmo/from/ > > And please consider moving local variables towards reverse xmas tree - > longest line to shortest - order for networking code. They were not ordered in the first place, so you prefer me to re-shuffle all of them (a bit independent change)? Best regards, Krzysztof
On Sun, May 14, 2023 at 11:15:40AM +0200, Krzysztof Kozlowski wrote: > On 14/05/2023 10:29, Simon Horman wrote: > > On Sat, May 13, 2023 at 01:51:12PM +0200, Krzysztof Kozlowski wrote: > >> On 13/05/2023 13:49, Krzysztof Kozlowski wrote: > >>> If sock->service_name is NULL, the local variable > >>> service_name_tlv_length will not be assigned by nfc_llcp_build_tlv(), > >>> later leading to using value frmo the stack. Smatch warning: > >>> > >>> net/nfc/llcp_commands.c:442 nfc_llcp_send_connect() error: uninitialized symbol 'service_name_tlv_length'. > >> > >> Eh, typo in subject prefix. V2 in shortly... > > > > Also, s/frmo/from/ > > > > And please consider moving local variables towards reverse xmas tree - > > longest line to shortest - order for networking code. > > They were not ordered in the first place, so you prefer me to re-shuffle > all of them (a bit independent change)? My slight preference is to move them towards being ordered. Maybe that is not practical in this case. As you point out, they are currently out of order. And if you think re-shuffling can be done, without excess churn, I think that would be fine. Given the current state of the code, reverse xmas tree is much more of a suggestion than a requirement form my side.
diff --git a/net/nfc/llcp_commands.c b/net/nfc/llcp_commands.c index 41e3a20c8935..cdb001de0692 100644 --- a/net/nfc/llcp_commands.c +++ b/net/nfc/llcp_commands.c @@ -390,7 +390,8 @@ int nfc_llcp_send_connect(struct nfc_llcp_sock *sock) const u8 *service_name_tlv = NULL; const u8 *miux_tlv = NULL; const u8 *rw_tlv = NULL; - u8 service_name_tlv_length, miux_tlv_length, rw_tlv_length, rw; + u8 service_name_tlv_length = 0; + u8 miux_tlv_length, rw_tlv_length, rw; int err; u16 size = 0; __be16 miux;