[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210521010752.lky4pz7zipefrfr7@ast-mbp>
Date: Thu, 20 May 2021 18:07:52 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Pavel Begunkov <asml.silence@...il.com>
Cc: io-uring@...r.kernel.org, netdev@...r.kernel.org,
bpf@...r.kernel.org, linux-kernel@...r.kernel.org,
Jens Axboe <axboe@...nel.dk>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Horst Schirmeier <horst.schirmeier@...dortmund.de>,
"Franz-B . Tuneke" <franz-bernhard.tuneke@...dortmund.de>,
Christian Dietrich <stettberger@...ucode.de>
Subject: Re: [PATCH 15/23] io_uring: enable BPF to submit SQEs
On Wed, May 19, 2021 at 03:13:26PM +0100, Pavel Begunkov wrote:
>
> +BPF_CALL_3(io_bpf_queue_sqe, struct io_bpf_ctx *, bpf_ctx,
> + const struct io_uring_sqe *, sqe,
> + u32, sqe_len)
> +{
> + struct io_ring_ctx *ctx = bpf_ctx->ctx;
> + struct io_kiocb *req;
> +
> + if (sqe_len != sizeof(struct io_uring_sqe))
> + return -EINVAL;
> +
> + req = io_alloc_req(ctx);
that is GFP_KERNEL allocation.
It's only allowed from sleepable bpf progs and further down
there is a correct check for it, so all good.
But submitting sqe is a fundemntal io_uring operation,
so what is the use case for non-sleepable?
In other words why bother? Allow sleepable only and simplify the code?
> + if (unlikely(!req))
> + return -ENOMEM;
> + if (!percpu_ref_tryget_many(&ctx->refs, 1)) {
> + kmem_cache_free(req_cachep, req);
> + return -EAGAIN;
> + }
> + percpu_counter_add(¤t->io_uring->inflight, 1);
> + refcount_add(1, ¤t->usage);
> +
> + /* returns number of submitted SQEs or an error */
> + return !io_submit_sqe(ctx, req, sqe);
A buggy bpf prog will be able to pass junk sizeof(struct io_uring_sqe)
as 'sqe' here.
What kind of validation io_submit_sqe() does to avoid crashing the kernel?
General comments that apply to all patches:
- commit logs are way too terse. Pls expand with details.
- describe new bpf helpers in comments in bpf.h. Just adding them to an enum is not enough.
- selftest/bpf are mandatory for all new bpf features.
- consider bpf_link style of attaching bpf progs. We had enough issues with progs
that get stuck due to application bugs. Auto-detach saves the day more often than not.
Powered by blists - more mailing lists