From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C49766FBB for ; Tue, 10 Jan 2023 18:19:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 484DCC433D2; Tue, 10 Jan 2023 18:19:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1673374751; bh=hUoYY6F6FpWJZB58X7VFaaWni/kn8cgpFMjjLid3rVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nZvwZX493OKTEP1OZtUlTae06VWtvdQm1Vwuz7DgOnwPOwGAksRJSoMZS8eYPO2pB LpMMuugrTaoRqda0IQj9BY+VeeQ1lOtFGMZ30IIvywddHLk5S07U7HBh2GD2hfThRH mNmTouZlYGssee02VngtuG5uXPDecj6wipT10VPg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jens Axboe , Sasha Levin Subject: [PATCH 6.1 121/159] io_uring: check for valid register opcode earlier Date: Tue, 10 Jan 2023 19:04:29 +0100 Message-Id: <20230110180022.175777075@linuxfoundation.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230110180018.288460217@linuxfoundation.org> References: <20230110180018.288460217@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Jens Axboe [ Upstream commit 343190841a1f22b96996d9f8cfab902a4d1bfd0e ] We only check the register opcode value inside the restricted ring section, move it into the main io_uring_register() function instead and check it up front. Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- io_uring/io_uring.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 71f1cabb9f3d..1bc68dfda340 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3897,8 +3897,6 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode, return -EEXIST; if (ctx->restricted) { - if (opcode >= IORING_REGISTER_LAST) - return -EINVAL; opcode = array_index_nospec(opcode, IORING_REGISTER_LAST); if (!test_bit(opcode, ctx->restrictions.register_op)) return -EACCES; @@ -4054,6 +4052,9 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode, long ret = -EBADF; struct fd f; + if (opcode >= IORING_REGISTER_LAST) + return -EINVAL; + f = fdget(fd); if (!f.file) return -EBADF; -- 2.35.1