From: Roberto Sassu <roberto.sassu@huaweicloud.com>
To: Eric Biggers <ebiggers@kernel.org>
Cc: dhowells@redhat.com, herbert@gondor.apana.org.au,
davem@davemloft.net, zohar@linux.ibm.com,
dmitry.kasatkin@gmail.com, paul@paul-moore.com,
jmorris@namei.org, serge@hallyn.com,
linux-integrity@vger.kernel.org,
linux-security-module@vger.kernel.org, keyrings@vger.kernel.org,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
Roberto Sassu <roberto.sassu@huawei.com>,
stable@vger.kernel.org
Subject: Re: [PATCH v2] KEYS: asymmetric: Copy sig and digest in public_key_verify_signature()
Date: Mon, 12 Dec 2022 10:07:38 +0100 [thread overview]
Message-ID: <fa8a307541735ec9258353d8ccb75c20bb22aafe.camel@huaweicloud.com> (raw)
In-Reply-To: <Y5OGr59A9wo86rYY@sol.localdomain>
On Fri, 2022-12-09 at 11:04 -0800, Eric Biggers wrote:
> On Fri, Dec 09, 2022 at 04:06:33PM +0100, Roberto Sassu wrote:
> > + /* key is used to store the sig and digest too. */
> > + key = kmalloc(key_max_len, GFP_KERNEL);
> > if (!key)
> > goto error_free_req;
>
> Maybe just call this 'buf', as the key is just one of the purposes the buffer is
> used for now.
Yes, better.
> > + /* Cannot use one scatterlist. The first needs to be s->s_size long. */
> > + sg_set_buf(&src_sg[0], key, sig->s_size);
> > + sg_set_buf(&src_sg[1], key + sig->s_size, sig->digest_size);
> > akcipher_request_set_crypt(req, src_sg, NULL, sig->s_size,
> > sig->digest_size);
>
> AFAIK, none of the crypto APIs that operate on 'scatterlist' are supposed to
> care how the data is divided up into scatterlist elements. So it sounds like
> there is another bug that needs to be fixed. It should be fixed, not worked
> around.
The problem is a misalignment between req->src_len (set to sig->s_size
by akcipher_request_set_crypt()) and the length of the scatterlist (if
we set the latter to sig->s_size + sig->digest_size).
When rsa_enc() calls mpi_read_raw_from_sgl(), it passes req->src_len as
argument, and the latter allocates the MPI according to that. However,
it does parsing depending on the length of the scatterlist.
If there are two scatterlists, it is not a problem, there is no
misalignment. mpi_read_raw_from_sgl() picks the first. If there is just
one, mpi_read_raw_from_sgl() parses all data there.
Roberto
next prev parent reply other threads:[~2022-12-12 9:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-09 15:06 [PATCH v2] KEYS: asymmetric: Copy sig and digest in public_key_verify_signature() Roberto Sassu
2022-12-09 19:04 ` Eric Biggers
2022-12-12 9:07 ` Roberto Sassu [this message]
2022-12-12 9:15 ` Herbert Xu
2022-12-19 8:49 ` Roberto Sassu
2022-12-20 7:24 ` [PATCH] lib/mpi: Fix buffer overrun when SG is too long Herbert Xu
2022-12-20 10:36 ` Roberto Sassu
2022-12-20 20:30 ` Eric Biggers
2022-12-21 6:53 ` [v2 PATCH] " Herbert Xu
2022-12-21 20:53 ` Eric Biggers
2022-12-23 6:25 ` Herbert Xu
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=fa8a307541735ec9258353d8ccb75c20bb22aafe.camel@huaweicloud.com \
--to=roberto.sassu@huaweicloud.com \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=dmitry.kasatkin@gmail.com \
--cc=ebiggers@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=jmorris@namei.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=roberto.sassu@huawei.com \
--cc=serge@hallyn.com \
--cc=stable@vger.kernel.org \
--cc=zohar@linux.ibm.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;
as well as URLs for NNTP newsgroup(s).