All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jesse Brandeburg <jesse.brandeburg@intel.com>
To: Michal Kubecek <mkubecek@suse.cz>
Cc: <netdev@vger.kernel.org>
Subject: Re: [PATCH ethtool v2 07/13] ethtool: avoid null pointer dereference
Date: Fri, 9 Dec 2022 09:36:54 -0800	[thread overview]
Message-ID: <c62825b9-e2b2-9293-e36e-c34d83c0d7e6@intel.com> (raw)
In-Reply-To: <20221208062312.2emtsvurflldumsr@lion.mk-sys.cz>

On 12/7/2022 10:23 PM, Michal Kubecek wrote:
> On Wed, Dec 07, 2022 at 05:11:16PM -0800, Jesse Brandeburg wrote:
>> '$ scan-build make' reports:
>>
>> Description: Array access (from variable 'arg') results in a null
>> pointer dereference
>> File: /git/ethtool/netlink/parser.c
>> Line: 782
>>
>> Description: Dereference of null pointer (loaded from variable 'p')
>> File: /git/ethtool/netlink/parser.c
>> Line: 794
>>
>> Both of these bugs are prevented by checking the input in
>> nl_parse_char_bitset(), which is called from nl_sset() via the kernel
>> callback, specifically for the parsing of the wake-on-lan options (-s
>> wol). None of the other functions in this file seem to have the issue of
>> deferencing data without checking for validity first. This could
>> "technically" allow nlctxt->argp to be NULL, and scan-build is limited
>> in it's ability to parse for bugs only at file scope in this case.
>> This particular bug should be unlikely to happen because the kernel
>> builds/parses the netlink structure before handing it to the
> 
> Again: this has nothing to do with netlink, this is command line parser,
> nlctx->argp is a member of argv[] array. And as execve() (which is the
> only syscall in the exec* family, the rest are wrappers) does not pass
> argc, only argv[], argc is actually determined by kernel so for it to be
> actually null, you would need a serious bug in kernel first.

Thank you for explaining! I can drop this patch, but it's disappointing 
that one fairly cheap conditional will prevent us from being able to 
cleanly run scan-build. If you have any other suggestions please let me 
know (and see below)

I spent some time today trying to get the command line to pass a NULL 
value but I couldn't do it, and elsewhere in the code the checks for 
argc prevent the NULL value or no value from getting into the ethtool 
code parsing the commands, so in this case it's not really a false 
positive, but taken care of by other code that isn't observable to the 
scan-build virtual machine. The good news is I don't see a real issue here.

> Even if we want to be safe against buggy kernel passing garbage as
> command line arguments, I still believe we should do that earlier, in
> the general code, not deep in a specific helper function. Also, you only
> check for null but that does not catch an invalid pointer in argv[]
> which, unlike a null pointer, could do an actual harm. And I don't see
> how that could be checked, I'm afraid we have to trust kernel.

OK, let's trust the kernel, but can we still fix this issue in order to 
be able to add scan-build to a list of tools to run cleanly in automation?

some TL;DR details in case there is someone else that has a suggestion!

Here is the callchain, for reference:
This is from the command
# ethtool -s eth0 wol pumbag

#0  nl_parse_char_bitset
#1  in nl_parser at netlink/parser.c:1099
#2  in nl_sset at netlink/settings.c:1247
#3  in netlink_run_handler at netlink/netlink.c:493
#4  in main at ethtool.c:6425

and in the #0 frame above, *nlctx->argp = "pumbag"
in the callchain above, scan-build doesn't like us de-referencing argp 
because it doesn't have proof it's not null.

Further I tried putting the check in every element of the stack frame 
above and they all fail the scan-build check still, probably because the 
pointer is advanced to the "pumbag" argument later in the code.

Anyway, I'm still working on the v3 of the series.


  reply	other threads:[~2022-12-09 17:37 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-08  1:11 [PATCH ethtool v2 00/13] ethtool: clean up and fix Jesse Brandeburg
2022-12-08  1:11 ` [PATCH ethtool v2 01/13] ethtool: convert boilerplate licenses to SPDX Jesse Brandeburg
2022-12-08  8:17   ` Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 02/13] ethtool: fix trivial issue in allocation Jesse Brandeburg
2022-12-08  8:26   ` Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 03/13] ethtool: disallow passing null to find_option Jesse Brandeburg
2022-12-08  9:14   ` Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 04/13] ethtool: commonize power related strings Jesse Brandeburg
2022-12-08 10:25   ` Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 05/13] ethtool: fix extra warnings Jesse Brandeburg
2022-12-08 10:43   ` Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 06/13] ethtool: fix uninitialized local variable use Jesse Brandeburg
2022-12-08  2:06   ` Andrew Lunn
2022-12-08  1:11 ` [PATCH ethtool v2 07/13] ethtool: avoid null pointer dereference Jesse Brandeburg
2022-12-08  6:23   ` Michal Kubecek
2022-12-09 17:36     ` Jesse Brandeburg [this message]
2022-12-09 18:06       ` Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 08/13] ethtool: fix runtime errors found by sanitizers Jesse Brandeburg
2022-12-08  6:34   ` Michal Kubecek
2022-12-09 17:42     ` Jesse Brandeburg
2022-12-09 18:09       ` Michal Kubecek
2022-12-09 22:09         ` Jesse Brandeburg
2022-12-08  1:11 ` [PATCH ethtool v2 09/13] ethtool: merge uapi changes to implement BIT and friends Jesse Brandeburg
2022-12-08  6:44   ` Michal Kubecek
2022-12-09 17:53     ` Jesse Brandeburg
2022-12-08  1:11 ` [PATCH ethtool v2 10/13] ethtool: refactor bit shifts to use BIT and BIT_ULL Jesse Brandeburg
2022-12-08  1:11 ` [PATCH ethtool v2 11/13] ethtool: fix missing free of memory after failure Jesse Brandeburg
2022-12-08 10:52   ` Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 12/13] ethtool: fix leak of memory after realloc Jesse Brandeburg
2022-12-08 11:30   ` Michal Kubecek
2022-12-08  1:11 ` [PATCH ethtool v2 13/13] ethtool: fix bug and use standard string parsing Jesse Brandeburg
2022-12-08 11:48   ` Michal Kubecek

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=c62825b9-e2b2-9293-e36e-c34d83c0d7e6@intel.com \
    --to=jesse.brandeburg@intel.com \
    --cc=mkubecek@suse.cz \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.