Linux wireless drivers development
 help / color / mirror / Atom feed
From: trix@redhat.com
To: johannes@sipsolutions.net, davem@davemloft.net, kuba@kernel.org,
	nathan@kernel.org, ndesaulniers@google.com,
	cjhuang@codeaurora.org, briannorris@chromium.org,
	kuabhs@chromium.org
Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, llvm@lists.linux.dev,
	Tom Rix <trix@redhat.com>
Subject: [PATCH] nl80211: check return of nla_parse_nested
Date: Fri, 18 Feb 2022 08:30:45 -0800	[thread overview]
Message-ID: <20220218163045.3370662-1-trix@redhat.com> (raw)

From: Tom Rix <trix@redhat.com>

Clang static analysis reports this representative problem
nl80211.c:15426:6: warning: Branch condition evaluates
  to a garbage value
  if (!tb[NL80211_SAR_ATTR_TYPE] ||
       ^~~~~~~~~~~~~~~~~~~~~~~~~~

tb is set when nla_parse_nested() is successful.
So check.

Fixes: 6bdb68cef7bf ("nl80211: add common API to configure SAR power limitations")
Signed-off-by: Tom Rix <trix@redhat.com>
---
 net/wireless/nl80211.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 7543c73a3f1d..c1532c8eb657 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -15419,9 +15419,11 @@ static int nl80211_set_sar_specs(struct sk_buff *skb, struct genl_info *info)
 	if (!info->attrs[NL80211_ATTR_SAR_SPEC])
 		return -EINVAL;
 
-	nla_parse_nested(tb, NL80211_SAR_ATTR_MAX,
-			 info->attrs[NL80211_ATTR_SAR_SPEC],
-			 NULL, NULL);
+	err = nla_parse_nested(tb, NL80211_SAR_ATTR_MAX,
+			       info->attrs[NL80211_ATTR_SAR_SPEC],
+			       NULL, NULL);
+	if (err)
+		return err;
 
 	if (!tb[NL80211_SAR_ATTR_TYPE] || !tb[NL80211_SAR_ATTR_SPECS])
 		return -EINVAL;
@@ -15444,8 +15446,10 @@ static int nl80211_set_sar_specs(struct sk_buff *skb, struct genl_info *info)
 	sar_spec->type = type;
 	specs = 0;
 	nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) {
-		nla_parse_nested(spec, NL80211_SAR_ATTR_SPECS_MAX,
-				 spec_list, NULL, NULL);
+		err = nla_parse_nested(spec, NL80211_SAR_ATTR_SPECS_MAX,
+				       spec_list, NULL, NULL);
+		if (err)
+			goto error;
 
 		switch (type) {
 		case NL80211_SAR_TYPE_POWER:
-- 
2.26.3


             reply	other threads:[~2022-02-18 16:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-18 16:30 trix [this message]
2022-02-18 16:51 ` [PATCH] nl80211: check return of nla_parse_nested Johannes Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220218163045.3370662-1-trix@redhat.com \
    --to=trix@redhat.com \
    --cc=briannorris@chromium.org \
    --cc=cjhuang@codeaurora.org \
    --cc=davem@davemloft.net \
    --cc=johannes@sipsolutions.net \
    --cc=kuabhs@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox