From patchwork Mon Aug 17 15:10:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 266535 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B574AC433DF for ; Mon, 17 Aug 2020 15:21:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8063420716 for ; Mon, 17 Aug 2020 15:21:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597677662; bh=ZQqVU7TG/KpLcPr0o/0mZ3eI0AAOkC63u17RKU6K1lI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=bG51vnJBjnrkyJKi0FuUer6WFRhr/0LrKMJY1/YmMj7YVIooiwqbOlvX1I9qVxbGL TfzGk9CIyHvq3NsQIB00QUVM5RT2vb1IMrChPvzxDIc6EPA44yykaBnJXZ6bN3Q8XB 4AdhIwZuHvWQvaNXbSLkvpWwhwppsO+Y9XRlHNVo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729307AbgHQPU6 (ORCPT ); Mon, 17 Aug 2020 11:20:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:42004 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729302AbgHQPUw (ORCPT ); Mon, 17 Aug 2020 11:20:52 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5AE9920729; Mon, 17 Aug 2020 15:20:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597677651; bh=ZQqVU7TG/KpLcPr0o/0mZ3eI0AAOkC63u17RKU6K1lI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fJ9lE/uw/pVaEbSP5J41Zs2Q/K/3vwu5ea7Sm3dAL7bFsr3R//8QcYTE+6a3L/Fku IcRczP5BezhIjvHinMHcq2F+Pk2eqzTiSuVcDBkaIOLLh7nkRBvEAEyGuRuUyuTM3L dw+t4I4PTOywe/cs7atFcBRvu/V+kWsTHGyxjMkk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Vyukov , Hristo Venev , io-uring@vger.kernel.org, Jens Axboe , Sasha Levin Subject: [PATCH 5.8 052/464] io_uring: fix sq array offset calculation Date: Mon, 17 Aug 2020 17:10:05 +0200 Message-Id: <20200817143836.252163777@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Dmitry Vyukov [ Upstream commit b36200f543ff07a1cb346aa582349141df2c8068 ] rings_size() sets sq_offset to the total size of the rings (the returned value which is used for memory allocation). This is wrong: sq array should be located within the rings, not after them. Set sq_offset to where it should be. Fixes: 75b28affdd6a ("io_uring: allocate the two rings together") Signed-off-by: Dmitry Vyukov Acked-by: Hristo Venev Cc: io-uring@vger.kernel.org Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 95bacab047ddb..8503aec7ea295 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7093,6 +7093,9 @@ static unsigned long rings_size(unsigned sq_entries, unsigned cq_entries, return SIZE_MAX; #endif + if (sq_offset) + *sq_offset = off; + sq_array_size = array_size(sizeof(u32), sq_entries); if (sq_array_size == SIZE_MAX) return SIZE_MAX; @@ -7100,9 +7103,6 @@ static unsigned long rings_size(unsigned sq_entries, unsigned cq_entries, if (check_add_overflow(off, sq_array_size, &off)) return SIZE_MAX; - if (sq_offset) - *sq_offset = off; - return off; }