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 F2D54A93F for ; Tue, 10 Jan 2023 18:11:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A730C433F0; Tue, 10 Jan 2023 18:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1673374274; bh=eTul3JhgtCBxB7GAR+jgLpBfGozJx5b7tq2cmV2RYkw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u3L8lygNqtsjeVGfo+BeGVJfp0DwXaeE11/9caURhF6EyES2rFazIEhzLgBGSndgd 52/gqlQWK7Gafh0OkLGNTC2mib3v9enhW/thoma9nDAuUw3y2EmYO6kgxiqfKEj8P8 37aVlmADY8KO1ZFKkui6gKAdZLMb63HB3ynl0UQE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jens Axboe , Sasha Levin Subject: [PATCH 6.0 112/148] io_uring: check for valid register opcode earlier Date: Tue, 10 Jan 2023 19:03:36 +0100 Message-Id: <20230110180020.740551695@linuxfoundation.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230110180017.145591678@linuxfoundation.org> References: <20230110180017.145591678@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 b8a39be3bcb4..cfcf1d415521 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3725,8 +3725,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; @@ -3882,6 +3880,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