From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: Daniel Borkmann <daniel@iogearbox.net>, ast@kernel.org
Cc: andrii@kernel.org, bpf@vger.kernel.org,
Stanislav Fort <disclosure@aisle.com>
Subject: Re: [PATCH bpf 1/2] bpf: Fix out-of-bounds dynptr write in bpf_crypto_crypt
Date: Fri, 29 Aug 2025 16:34:45 +0100 [thread overview]
Message-ID: <9a3d321e-b8d6-4a64-a1f1-fc44d9d7848e@linux.dev> (raw)
In-Reply-To: <cacb4948-fb97-4bb4-8147-f38245ec3826@iogearbox.net>
On 29/08/2025 16:30, Daniel Borkmann wrote:
> On 8/29/25 4:50 PM, Vadim Fedorenko wrote:
>> On 29/08/2025 15:36, Daniel Borkmann wrote:
>>> Stanislav reported that in bpf_crypto_crypt() the destination dynptr's
>>> size is not validated to be at least as large as the source dynptr's
>>> size before calling into the crypto backend with 'len = src_len'. This
>>> can result in an OOB write when the destination is smaller than the
>>> source.
>>>
>>> Concretely, in mentioned function, psrc and pdst are both linear
>>> buffers fetched from each dynptr:
>>>
>>> psrc = __bpf_dynptr_data(src, src_len);
>>> [...]
>>> pdst = __bpf_dynptr_data_rw(dst, dst_len);
>>> [...]
>>> err = decrypt ?
>>> ctx->type->decrypt(ctx->tfm, psrc, pdst, src_len, piv) :
>>> ctx->type->encrypt(ctx->tfm, psrc, pdst, src_len, piv);
>>>
>>> The crypto backend expects pdst to be large enough with a src_len length
>>> that can be written. Add an additional src_len > dst_len check and bail
>>> out if it's the case. Note that these kfuncs are accessible under root
>>> privileges only.
>>>
>>> Fixes: 3e1c6f35409f ("bpf: make common crypto API for TC/XDP programs")
>>> Reported-by: Stanislav Fort <disclosure@aisle.com>
>>> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
>>> Cc: Vadim Fedorenko <vadim.fedorenko@linux.dev>
>>> ---
>>> kernel/bpf/crypto.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/kernel/bpf/crypto.c b/kernel/bpf/crypto.c
>>> index 94854cd9c4cc..83c4d9943084 100644
>>> --- a/kernel/bpf/crypto.c
>>> +++ b/kernel/bpf/crypto.c
>>> @@ -278,7 +278,7 @@ static int bpf_crypto_crypt(const struct
>>> bpf_crypto_ctx *ctx,
>>> siv_len = siv ? __bpf_dynptr_size(siv) : 0;
>>> src_len = __bpf_dynptr_size(src);
>>> dst_len = __bpf_dynptr_size(dst);
>>> - if (!src_len || !dst_len)
>>> + if (!src_len || !dst_len || src_len > dst_len)
>>
>> I think it would make sense to have less restrictive check. I mean it's
>> ok to have dst_len equal to src_len.
>
> That scenario is/remains allowed and is also what the 'good' case is
> testing in
> the BPF selftests (src_len 16 vs dst_len 16).
Ah, sorry, misread the code. Yeah, it makes sense.
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
next prev parent reply other threads:[~2025-08-29 15:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-29 14:36 [PATCH bpf 1/2] bpf: Fix out-of-bounds dynptr write in bpf_crypto_crypt Daniel Borkmann
2025-08-29 14:36 ` [PATCH bpf 2/2] selftests/bpf: Extend crypto_sanity selftest with invalid dst buffer Daniel Borkmann
2025-08-29 14:50 ` [PATCH bpf 1/2] bpf: Fix out-of-bounds dynptr write in bpf_crypto_crypt Vadim Fedorenko
2025-08-29 15:30 ` Daniel Borkmann
2025-08-29 15:34 ` Vadim Fedorenko [this message]
2025-08-29 17:30 ` 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=9a3d321e-b8d6-4a64-a1f1-fc44d9d7848e@linux.dev \
--to=vadim.fedorenko@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=disclosure@aisle.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).