Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4162715pxk; Tue, 8 Sep 2020 12:16:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwClhrUJN8pvOvTIJC32M8FmJaKLYS6ZA1M2aK3HUKdydehzFbn9t7s0os/4yt6pvsIPEzG X-Received: by 2002:aa7:cf05:: with SMTP id a5mr487054edy.313.1599592619354; Tue, 08 Sep 2020 12:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599592619; cv=none; d=google.com; s=arc-20160816; b=SVHugYDazl2GYxRyZ5Am7rzK8cvFHDjFWhJvzv7NNoVFvyLJOgU6wJVsvsJy/9DUYW lYicQi/rgJyEDUNUUXRg/t1PSk22Ba+em1adsp+o8DgVvSLl+UcxBf25j6eBV73i1lS6 xeXHPExP4jTN2tRnPcwMYDqEGhDf7qwhFkqK2gHsmtNgQUHkTzAR2gxGT3AjMZTrkGiX 5/w1LC1qOJPWD2L9d5niwg+jDz0CPVJrEJo0z4ErIQCMQV8whMvcFgVzBoiyCxqpjpR1 azcI7kl+yk0PPvRBh3dLo95XoN2doYhKuo452YN2nI8Ti7nhwukmWBkTvrR8WItwL8VD fzkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=0nFHBAUKZtW6gfmKK0htBo0gwbtsv3Iq0Ml6HLLohY8=; b=KFoF1FNKz2N/jidFdZWJRGuIY2dAPg4o0oz2e9gicxD6NUuHqe25JGT8FRcrR42mJt 64s5026h8CWtEA61UQ1/oCH4KKdN/uBqIhVMRavYZsvsfwmhQWeQWqKM1fSEQXYIFpXs 1oBj1P98V4G/iEQpspjJj0U4IG74hYP/JODa/j2IDSo+xnM+uy3h7mAOb9S7CQ6lk5db cP5lRq760EjJ/4/jWfLbLYG77BIM15y1MQyx9WGVuuyZjD8HajULeyYnlMF9YPi77SY+ 37VzU189V5WD0PGfpt2PbKHpbR4a0kpiZxOyELhrDhcxdKf96GFa+THjCKvSOaOpvPyi qCOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Pn4A1LX6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s10si4750331ejr.574.2020.09.08.12.16.35; Tue, 08 Sep 2020 12:16:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Pn4A1LX6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725997AbgIHTOy (ORCPT + 99 others); Tue, 8 Sep 2020 15:14:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59663 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731197AbgIHQEv (ORCPT ); Tue, 8 Sep 2020 12:04:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599581086; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0nFHBAUKZtW6gfmKK0htBo0gwbtsv3Iq0Ml6HLLohY8=; b=Pn4A1LX68rOZ64MG9Sw2kVJ1k73IzTGWO+Vw9D+dG8a5T2udNYG7xRPnMbuWVCIlr/hL4O ZEDejS1sih3x3iNaIuP0SPHj8g61WJZcz+stXqyzymhX+bAhQsNoil93bj1OF5/gGe9WQU TMNE1ll/BgO4RngVadNV3/6nUlWD8bs= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-462-ojrsyBxoPOuyIGvkDIsFZw-1; Tue, 08 Sep 2020 09:44:53 -0400 X-MC-Unique: ojrsyBxoPOuyIGvkDIsFZw-1 Received: by mail-wm1-f69.google.com with SMTP id b73so3502806wmb.0 for ; Tue, 08 Sep 2020 06:44:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=0nFHBAUKZtW6gfmKK0htBo0gwbtsv3Iq0Ml6HLLohY8=; b=IVhSXjzIKC9Wo/UJjHyTIo0uCZL4LL52v41cDlsxghYFpDHcmfQJcFIYBP/cZ9LYLg 0dm4EXuNwXTbzDhMHsbClRb3p/9jrQvKprRQFp1QhgzwDWGXgte+FDLH+R+WPU3JpDqb A3lwWmGcCSrDnKnMxI2JCVQOsqs/yPKTyhO9pStlyLjarRKKXkYSxP6II+FiKe9jN53f tchIMOtQD5DTfG8zWML5uVn6XP/ibK7/6ycv71gJ6T4PP/NoYd1JKWXkspqBd4toI0EQ RUFDUOc3PC/kHtn54DodeDbLbuUyZnZUpS7cnNTSnVIbtZg+v5FBKYcXyhf1dI+9Epjp QuGg== X-Gm-Message-State: AOAM5313noDH/mctpWEODSy13PwEKtpL1Ne/tL0AKVj2J8rBgTI8KcF2 raxSv1n3JczdKhMS49QU21g7Vk8xSUt7SE7ctez+yqZGfGgsRKNYMsa2QGOW9hEnxkVgGkPUWaD lfoXldw2ObCqmPxZRuCxNZk5C X-Received: by 2002:a5d:680e:: with SMTP id w14mr25476338wru.50.1599572692188; Tue, 08 Sep 2020 06:44:52 -0700 (PDT) X-Received: by 2002:a5d:680e:: with SMTP id w14mr25476320wru.50.1599572691912; Tue, 08 Sep 2020 06:44:51 -0700 (PDT) Received: from steredhat (host-79-53-225-185.retail.telecomitalia.it. [79.53.225.185]) by smtp.gmail.com with ESMTPSA id a83sm31806176wmh.48.2020.09.08.06.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 06:44:51 -0700 (PDT) Date: Tue, 8 Sep 2020 15:44:48 +0200 From: Stefano Garzarella To: Jens Axboe Cc: Kernel Hardening , Christian Brauner , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Alexander Viro , Stefan Hajnoczi , Jann Horn , Jeff Moyer , Aleksa Sarai , Sargun Dhillon , linux-kernel@vger.kernel.org, Kees Cook Subject: Re: [PATCH v6 3/3] io_uring: allow disabling rings during the creation Message-ID: <20200908134448.sg7evdrfn6xa67sn@steredhat> References: <20200827145831.95189-1-sgarzare@redhat.com> <20200827145831.95189-4-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200827145831.95189-4-sgarzare@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jens, On Thu, Aug 27, 2020 at 04:58:31PM +0200, Stefano Garzarella wrote: > This patch adds a new IORING_SETUP_R_DISABLED flag to start the > rings disabled, allowing the user to register restrictions, > buffers, files, before to start processing SQEs. > > When IORING_SETUP_R_DISABLED is set, SQE are not processed and > SQPOLL kthread is not started. > > The restrictions registration are allowed only when the rings > are disable to prevent concurrency issue while processing SQEs. > > The rings can be enabled using IORING_REGISTER_ENABLE_RINGS > opcode with io_uring_register(2). > > Suggested-by: Jens Axboe > Reviewed-by: Kees Cook > Signed-off-by: Stefano Garzarella > --- > v4: > - fixed io_uring_enter() exit path when ring is disabled > > v3: > - enabled restrictions only when the rings start > > RFC v2: > - removed return value of io_sq_offload_start() > --- > fs/io_uring.c | 52 ++++++++++++++++++++++++++++++----- > include/uapi/linux/io_uring.h | 2 ++ > 2 files changed, 47 insertions(+), 7 deletions(-) > > diff --git a/fs/io_uring.c b/fs/io_uring.c > index 5f62997c147b..b036f3373fbe 100644 > --- a/fs/io_uring.c > +++ b/fs/io_uring.c > @@ -226,6 +226,7 @@ struct io_restriction { > DECLARE_BITMAP(sqe_op, IORING_OP_LAST); > u8 sqe_flags_allowed; > u8 sqe_flags_required; > + bool registered; > }; > > struct io_ring_ctx { > @@ -7497,8 +7498,8 @@ static int io_init_wq_offload(struct io_ring_ctx *ctx, > return ret; > } > > -static int io_sq_offload_start(struct io_ring_ctx *ctx, > - struct io_uring_params *p) > +static int io_sq_offload_create(struct io_ring_ctx *ctx, > + struct io_uring_params *p) > { > int ret; > > @@ -7532,7 +7533,6 @@ static int io_sq_offload_start(struct io_ring_ctx *ctx, > ctx->sqo_thread = NULL; > goto err; > } > - wake_up_process(ctx->sqo_thread); > } else if (p->flags & IORING_SETUP_SQ_AFF) { > /* Can't have SQ_AFF without SQPOLL */ > ret = -EINVAL; > @@ -7549,6 +7549,12 @@ static int io_sq_offload_start(struct io_ring_ctx *ctx, > return ret; > } > > +static void io_sq_offload_start(struct io_ring_ctx *ctx) > +{ > + if ((ctx->flags & IORING_SETUP_SQPOLL) && ctx->sqo_thread) > + wake_up_process(ctx->sqo_thread); > +} > + > static inline void __io_unaccount_mem(struct user_struct *user, > unsigned long nr_pages) > { > @@ -8295,6 +8301,9 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, > if (!percpu_ref_tryget(&ctx->refs)) > goto out_fput; > > + if (ctx->flags & IORING_SETUP_R_DISABLED) > + goto out_fput; > + While writing the man page paragraph, I discovered that if the rings are disabled I returned ENXIO error in io_uring_enter(), coming from the previous check. I'm not sure it is the best one, maybe I can return EBADFD or another error. What do you suggest? I'll add a test for this case. Thanks, Stefano