From: Ivan Vecera <ivecera@redhat.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org,
Przemek Kitszel <przemyslaw.kitszel@intel.com>,
Jiri Pirko <jiri@resnulli.us>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Jonathan Corbet <corbet@lwn.net>,
Prathosh Satish <Prathosh.Satish@microchip.com>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
Michal Schmidt <mschmidt@redhat.com>,
Petr Oros <poros@redhat.com>
Subject: Re: [PATCH net-next v6 3/5] dpll: zl3073x: Add firmware loading functionality
Date: Mon, 15 Sep 2025 10:18:03 +0200 [thread overview]
Message-ID: <4bd1847b-00b6-42a6-8391-aba08aeb3721@redhat.com> (raw)
In-Reply-To: <20250914144549.2c8d7453@kernel.org>
On 14. 09. 25 11:45 odp., Jakub Kicinski wrote:
> On Tue, 9 Sep 2025 11:15:30 +0200 Ivan Vecera wrote:
>> + /* Fetch image name and size from input */
>> + strscpy(buf, *psrc, min(sizeof(buf), *psize));
>> + rc = sscanf(buf, "%15s %u %n", name, &count, &pos);
>> + if (!rc) {
>> + /* No more data */
>> + return 0;
>> + } else if (rc == 1 || count > U32_MAX / sizeof(u32)) {
>> + ZL3073X_FW_ERR_MSG(extack, "invalid component size");
>> + return -EINVAL;
>> + }
>> + *psrc += pos;
>> + *psize -= pos;
>
> Still worried about pos not being bounds checked.
> Admin can crash the kernel with invalid FW file.
>
> if (pos > *psize)
> /* error */
This cannot happen...
1) strscpy(buf, *psrc, min(sizeof(buf, *psize)) ensures that the string
will be zero padded and strlen(buf) will be less than *psize
2) sscanf(buf, "%15s %u %n", name, &count, &pos) scans for string with
max length of 15, one or more whitespace(s), number and one or more
whitespaces(s). And reports number of parsed arguments. Note that
the %n does not increase the count returned.
So... if:
1) buf is empty then sscanf returns 0 and /* No more data */ code path
is executed
2) buf contains only string (1st argument) OR string and non-numeric
2nd argument then the sscanf returns 1 and 'invalid component size'
is executed
3) buf contains string (1st arg) and numeric 2nd arg then the sscanf
returns 2 and the 2nd arg is stored into 'count' and number of
consumed characters into 'pos'
4) if 'count' > (U32_MAX / 4) then 'invalid component size' path is
executed
> Also what if sscanf() return 2? pos is uninitialized?
If the sscanf() returns 2 then pos is initialized, in other words
'pos' is initialized and less then *psize if the 'count' is correctly
parsed as the numeric value.
Thanks,
Ivan
next prev parent reply other threads:[~2025-09-15 8:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 9:15 [PATCH net-next v6 0/5] dpll: zl3073x: Add support for devlink flash Ivan Vecera
2025-09-09 9:15 ` [PATCH net-next v6 1/5] dpll: zl3073x: Add functions to access hardware registers Ivan Vecera
2025-09-09 9:15 ` [PATCH net-next v6 2/5] dpll: zl3073x: Add low-level flash functions Ivan Vecera
2025-09-09 9:15 ` [PATCH net-next v6 3/5] dpll: zl3073x: Add firmware loading functionality Ivan Vecera
2025-09-14 21:45 ` Jakub Kicinski
2025-09-15 8:18 ` Ivan Vecera [this message]
2025-09-15 15:08 ` Jakub Kicinski
2025-09-09 9:15 ` [PATCH net-next v6 4/5] dpll: zl3073x: Refactor DPLL initialization Ivan Vecera
2025-09-09 9:15 ` [PATCH net-next v6 5/5] dpll: zl3073x: Implement devlink flash callback Ivan Vecera
2025-09-15 15:30 ` [PATCH net-next v6 0/5] dpll: zl3073x: Add support for devlink flash 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=4bd1847b-00b6-42a6-8391-aba08aeb3721@redhat.com \
--to=ivecera@redhat.com \
--cc=Prathosh.Satish@microchip.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mschmidt@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=poros@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
/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
all inboxes | Powered by JetHome®