From patchwork Mon Jan 27 15:57:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hamza Mahfooz X-Patchwork-Id: 13951580 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3F51E14D6ED; Mon, 27 Jan 2025 15:59:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737993575; cv=none; b=OOB78cG+a5zAC7Ml6MzVA+f83zahAW7m4PTT1wbInVxqZ9iLg9NAZ9DvCsnLYWtio2PugMH2GpIA1VewfafUJAO7qy6Rr5BJQ3NlhuJ/ePAl4JQHO5dQ58fPJ5d/x/GkIbK4JyDMep5XeOSzwqv0xAhXYdgAXWZJect7NFYbn9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737993575; c=relaxed/simple; bh=H+g4ZMD0yhyfee4133CeWuDA9psgDECOgETg+acbf8c=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=DLaKXPPYlt1SQO80l24dw9VMhSncTXfWfdQAt5KTUdltcIUadlPPJ2iD82CjgLGtzoTxdr0BcGhi+wPY75OF6a9Vff2Yhh50HI8kjJWC5mi9LWsurZrv9CxEfRlN6iQSbn6U2+GuHZrMJURGlB0liOSbNkPjH9Y8x9TRtV6UWZ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=Ne6wBdfP; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="Ne6wBdfP" Received: from hm-sls2.corp.microsoft.com (unknown [184.146.177.43]) by linux.microsoft.com (Postfix) with ESMTPSA id 391DD20545AC; Mon, 27 Jan 2025 07:59:27 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 391DD20545AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1737993568; bh=VjAmq2kOp0FdSGzONSmhJBT9T9J4PGigVc+QqkE8Hg4=; h=From:To:Cc:Subject:Date:From; b=Ne6wBdfPgCNAVY8zJTkzZB0vL7nPZyMKZ+YDr+jMyYXOmaOFNdrloHzVgQSd6nlO+ 1rgQ37nJXRH6ekV9/k1e3vjc76DQ6Cky1pMq4gBKEfwIgmieLxCnePIF5WauDf53Bf jMW1QCNkr2s3xBXdoec1sG5UxpkQKt8NYVhnqH44= From: Hamza Mahfooz To: linux-kernel@vger.kernel.org Cc: Hamza Mahfooz , Jens Axboe , Paul Moore , James Morris , "Serge E. Hallyn" , Pavel Begunkov , Stephen Smalley , Ondrej Mosnacek , =?utf-8?q?Thi=C3=A9baud_Weksteen?= , =?utf-8?q?Christian_?= =?utf-8?q?G=C3=B6ttsche?= , =?utf-8?q?Bram_Bonn?= =?utf-8?q?=C3=A9?= , Masahiro Yamada , linux-security-module@vger.kernel.org, io-uring@vger.kernel.org, selinux@vger.kernel.org Subject: [PATCH v3 1/2] io_uring: refactor io_uring_allowed() Date: Mon, 27 Jan 2025 10:57:17 -0500 Message-ID: <20250127155723.67711-1-hamzamahfooz@linux.microsoft.com> X-Mailer: git-send-email 2.47.1 Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Have io_uring_allowed() return an error code directly instead of true/false. This is needed for follow-up work to guard io_uring_setup() with LSM. Cc: Jens Axboe Signed-off-by: Hamza Mahfooz --- io_uring/io_uring.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 7bfbc7c22367..c2d8bd4c2cfc 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3789,29 +3789,36 @@ static long io_uring_setup(u32 entries, struct io_uring_params __user *params) return io_uring_create(entries, &p, params); } -static inline bool io_uring_allowed(void) +static inline int io_uring_allowed(void) { int disabled = READ_ONCE(sysctl_io_uring_disabled); kgid_t io_uring_group; if (disabled == 2) - return false; + return -EPERM; if (disabled == 0 || capable(CAP_SYS_ADMIN)) - return true; + goto allowed_lsm; io_uring_group = make_kgid(&init_user_ns, sysctl_io_uring_group); if (!gid_valid(io_uring_group)) - return false; + return -EPERM; + + if (!in_group_p(io_uring_group)) + return -EPERM; - return in_group_p(io_uring_group); +allowed_lsm: + return 0; } SYSCALL_DEFINE2(io_uring_setup, u32, entries, struct io_uring_params __user *, params) { - if (!io_uring_allowed()) - return -EPERM; + int ret; + + ret = io_uring_allowed(); + if (ret) + return ret; return io_uring_setup(entries, params); }