From: Nicholas Vinson <nvinson234@gmail.com>
To: Michal Kubecek <mkubecek@suse.cz>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH ethtool 3/3] Fix potentinal null-pointer derference issues.
Date: Mon, 8 May 2023 08:48:43 -0400 [thread overview]
Message-ID: <805b69fb-9852-b209-3b45-680b60e3eb37@gmail.com> (raw)
In-Reply-To: <20230508074039.n6ofud6dbkuhe64x@lion.mk-sys.cz>
On 5/8/23 03:40, Michal Kubecek wrote:
> On Sun, May 07, 2023 at 10:46:05PM -0400, Nicholas Vinson wrote:
>> On 5/7/23 18:57, Michal Kubecek wrote:
>>> On Sun, Apr 30, 2023 at 06:50:52PM -0400, Nicholas Vinson wrote:
>>>> Found via gcc -fanalyzer. Analyzer claims that it's possible certain
>>>> functions may receive a NULL pointer when handling CLI arguments. Adding
>>>> NULL pointer checks to correct the issues.
>>>>
>>>> Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
>>> A similar theoretical issue was discussed recently:
>>>
>>> https://patchwork.kernel.org/project/netdevbpf/patch/20221208011122.2343363-8-jesse.brandeburg@intel.com/
>>>
>>> My position is still the same: argv[] members cannot be actually null
>>> unless there is a serious kernel bug (see the link above for an
>>> explanation). I'm not opposed to doing a sanity check just in case but
>>> if we do, I believe we should check the whole argv[] array right at the
>>> beginning and be done with it rather than add specific checks to random
>>> places inside parser code.
>> By convention and POSIX standard, the last argv[] member is always set to
>> NULL and is accessed from main(int argc, char **argp) via argp[argc] (see
>> https://pubs.opengroup.org/onlinepubs/9699919799/functions/execve.html).
>> It's also possible for argc to be zero. In such a case, find_option(NULL)
>> would get called.
> Please note that ethtool is not a utility for a general POSIX system.
> It is a very specific utility which works and makes sense only on Linux.
> That's why it can and does take many assumptions which are only
> guaranteed on Linux but may not be true on other POSIX systems.
>
>> However, after reviewing main(), I recommend changing:
>>
>> if (argc == 0)
>>
>> exit_bad_args();
>>
>> to
>>
>> if (argc <= 0 || !*argp)
>>
>> exit_bad_args();
>>
>>
>> as this fixes the potential issue of main()'s argc being 0 (argc would be -1
>> at this point in such cases), and "!*argp" silences gcc's built-in analyzer
>> (and should silence all other SA with respect to the reported issue) as the
>> SA doesn't recognize that it would take a buggy execve implementation to
>> allow argp to be NULL at this point ).
>>
>> If you don't have any objections to this change, I can draft an updated
>> patch to make this change.
> As I said before, I do not object to adding a sanity check of argc/argv,
> I only objected to adding random checks inside the parser code just to
> make static checkers happy. If you want to add (or strengthen) a sanity
> check right at the beginning of the program, before any parsing, I have
> no problem with that.
I am abandoning this patch in favor of a new one with the subject line
"[PATCH ethtool] Fix argc and argp handling issues".
Thanks,
Nicholas Vinson
> Michal
next prev parent reply other threads:[~2023-05-08 12:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-30 22:50 [PATCH ethtool 0/3] Fix issues found by gcc -fanalyze Nicholas Vinson
2023-04-30 22:50 ` [PATCH ethtool 1/3] Update FAM syntax to conform to std C Nicholas Vinson
2023-04-30 22:50 ` [PATCH ethtool 2/3] Fix reported memory leak Nicholas Vinson
2023-04-30 22:50 ` [PATCH ethtool 3/3] Fix potentinal null-pointer derference issues Nicholas Vinson
2023-05-07 22:57 ` Michal Kubecek
2023-05-08 2:46 ` Nicholas Vinson
2023-05-08 7:40 ` Michal Kubecek
2023-05-08 12:48 ` Nicholas Vinson [this message]
2023-05-07 22:40 ` [PATCH ethtool 0/3] Fix issues found by gcc -fanalyze patchwork-bot+netdevbpf
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=805b69fb-9852-b209-3b45-680b60e3eb37@gmail.com \
--to=nvinson234@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).