Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp740931rwr; Thu, 27 Apr 2023 07:37:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5DPUeONw9kFYMk3AHbxAjevgiRII03EsfSWN96uvI+AohTKqLRwWSFIn58KSvJ8+4R5Tul X-Received: by 2002:a17:902:e5c7:b0:1a9:6467:aa78 with SMTP id u7-20020a170902e5c700b001a96467aa78mr2119559plf.4.1682606229974; Thu, 27 Apr 2023 07:37:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682606229; cv=none; d=google.com; s=arc-20160816; b=vddb0M2zKIWuJWeM88sHfivZbQMEu26E3xCGSiW43lzs3FEsii12C7YcoWCQpq89id SeKvfAXhAlCUFOR/0ZkqLmv0X+lXhLdTWY/tonaerb4ARHEPQfjRdMsIn+f6ad/HNcNP tokMeGihJkO2pIMgHP+0dhm5enSG4umYJiYSiKHnED/iSGU9yWLwoGiLdV3PZkDlhlKT Xxr0tLUMwGEm5kM6V//BI3kQaUuS6voQLa+3zlQ4f5fATz8suQwmbnEenlSSW2LnEehI CBiTGuKMP+XbQE6Ukkl5jaAdtr8O4YGY5brz7xuysPEurKKVsI1RV1b7jxDlg6qf6OTw SekQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=kNT+ZBmU5N0WPZ8cBTggHlBfTwfHuCk18VxCzwhh2Lo=; b=U5hZNTkNgzYC9Ii1+wjGqD5FOohWKi0iRqONNq4+ZS3YY86i0hWo2zsbeS4lqaCj3N utZ4zk0Se4GXbN4UFIsF4dmXTulGMLTPBqHTUii0d8a7lm6ujZpNs+g5aJzdSr4979Dl YFx45n4tIV6K3qN2pWUdlz8HMPbhLJ37bit4Q2S6xkTi6gqFqHTJwaheJPMEpddKPGMO dSHgpWH/JcZVhft0nZ96FvSRgLDsQPHKz3opVRXyV7R47nQv0qwku8saj++zPYl8wfcE 7aW4/Gcsqid0JLtDR2It7eg0RxCGBIxOKrOHLQj4MVVgapJncL9imqxu1AR67QV5w6CC Q9gA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t4-20020a170902e84400b001a80ddd372csi20005582plg.43.2023.04.27.07.36.58; Thu, 27 Apr 2023 07:37:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243711AbjD0Ocm (ORCPT + 99 others); Thu, 27 Apr 2023 10:32:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244046AbjD0Och (ORCPT ); Thu, 27 Apr 2023 10:32:37 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DC7E04C2B; Thu, 27 Apr 2023 07:32:11 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5AA702F4; Thu, 27 Apr 2023 07:32:48 -0700 (PDT) Received: from e125637.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6DABC3F64C; Thu, 27 Apr 2023 07:32:03 -0700 (PDT) From: Tudor Cretu To: io-uring@vger.kernel.org Cc: =axboe@kernel.dk, asml.silence@gmail.com, kevin.brodsky@arm.com, linux-kernel@vger.kernel.org, Tudor Cretu Subject: [PATCH] io_uring/kbuf: Fix size for shared buffer ring Date: Thu, 27 Apr 2023 15:31:42 +0100 Message-Id: <20230427143142.3013020-1-tudor.cretu@arm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The size of the ring is the product of ring_entries and the size of struct io_uring_buf. Using struct_size is equivalent to (ring_entries + 1) * sizeof(struct io_uring_buf) and generates an off-by-one error. Fix it by using size_mul directly. Signed-off-by: Tudor Cretu --- io_uring/kbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c index 4a6401080c1f..9770757c89a0 100644 --- a/io_uring/kbuf.c +++ b/io_uring/kbuf.c @@ -505,7 +505,7 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg) } pages = io_pin_pages(reg.ring_addr, - struct_size(br, bufs, reg.ring_entries), + size_mul(sizeof(struct io_uring_buf), reg.ring_entries), &nr_pages); if (IS_ERR(pages)) { kfree(free_bl); -- 2.34.1