From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Thorsten Blum <thorsten.blum@linux.dev>
Cc: Giovanni Cabiddu <giovanni.cabiddu@intel.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Jack Xu <jack.xu@intel.com>,
Suman Kumar Chakraborty <suman.kumar.chakraborty@intel.com>,
Qianfeng Rong <rongqianfeng@vivo.com>,
qat-linux@intel.com, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: qat - use strscpy_pad to simplify buffer initialization
Date: Wed, 22 Oct 2025 21:29:31 +0300 [thread overview]
Message-ID: <aPkii_HgX1f0MUVc@smile.fi.intel.com> (raw)
In-Reply-To: <aPkfsuliKYy5UAbB@smile.fi.intel.com>
On Wed, Oct 22, 2025 at 09:17:22PM +0300, Andy Shevchenko wrote:
> On Wed, Oct 22, 2025 at 02:36:19PM +0200, Thorsten Blum wrote:
> > Use strscpy_pad() to copy the string and zero-pad the destination buffer
> > in a single step instead of zero-initializing the buffer first and then
> > immediately overwriting it using strscpy().
> >
> > Replace the magic number 16 with sizeof(buf) and remove the redundant
> > parentheses around kstrtoul() while we're at it.
>
> I understand that you focused on strscpy*() conversions, but the below I think
> needs a bigger refactoring, see my remarks.
...
> > - char buf[16] = {0};
> > + char buf[16] = {};
> > unsigned long ae = 0;
> > int i;
> >
> > - strscpy(buf, str, sizeof(buf));
> > - for (i = 0; i < 16; i++) {
> > + strscpy_pad(buf, str);
>
> First of all, why do we need a _pad() version here? Is the data somehow being
> used as a whole?
>
> > + for (i = 0; i < sizeof(buf); i++) {
> > if (!isdigit(buf[i])) {
> > buf[i] = '\0';
> > break;
> > }
> > }
> > - if ((kstrtoul(buf, 10, &ae)))
> > + if (kstrtoul(buf, 10, &ae))
> > return -EFAULT;
On top of that the function is called only from one place and returns different
error code, instead it would have returned what kstrtoul() gives...
> Looking at this, it tries to work around the kstrtoul() inability to perform
> partial parses. Instead, this should do something like
>
> unsigned long long x;
> const char *end;
>
> simple_strtoull(...);
> if (x > UINT_MAX || end == buf)
> return $ERR; // wrong input / overflow
Yeah, the overflow check here is not comprehensive, it won't catch the overflow
(wrap around) of 64-bit value. But we can add a check for the end not to be
farther than ~19 characters from the start, which would correspond the initial
copy of 16 characters.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-10-22 18:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-22 12:36 [PATCH] crypto: qat - use strscpy_pad to simplify buffer initialization Thorsten Blum
2025-10-22 18:17 ` Andy Shevchenko
2025-10-22 18:29 ` Andy Shevchenko [this message]
2025-10-23 15:35 ` Thorsten Blum
2025-10-23 18:44 ` Andy Shevchenko
2025-10-24 8:50 ` Giovanni Cabiddu
2025-10-24 9:49 ` Andy Shevchenko
2025-10-24 18:47 ` Thorsten Blum
2025-10-27 8:19 ` Andy Shevchenko
2025-10-27 8:43 ` Thorsten Blum
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=aPkii_HgX1f0MUVc@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=davem@davemloft.net \
--cc=giovanni.cabiddu@intel.com \
--cc=herbert@gondor.apana.org.au \
--cc=jack.xu@intel.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=qat-linux@intel.com \
--cc=rongqianfeng@vivo.com \
--cc=suman.kumar.chakraborty@intel.com \
--cc=thorsten.blum@linux.dev \
/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.