From patchwork Mon Aug 17 15:17:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 266375 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=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, 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 301ADC433E3 for ; Mon, 17 Aug 2020 16:09:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9D8322D2C for ; Mon, 17 Aug 2020 16:09:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597680574; bh=db7ks6C0AJctQO49/B+ps/2x8OHnvLRgvbnNsrSvoHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=VqDSPK9102kZUnoodW6C8FBFuJa/lqciLMIZ2BEjPC1Z6rs4sM6e/B+elMOLhFDPA NXwgHGu9ZWRAWv6BIsfMLMNhQzVlHgTXN2DOAWol7Mt1HIo3QxeieyioSSIYKqtX85 3za+88/M5s2yakTqYsM/Gzt/m99WMn0i7iwWhoF8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388311AbgHQQJa (ORCPT ); Mon, 17 Aug 2020 12:09:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:60644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388505AbgHQQJX (ORCPT ); Mon, 17 Aug 2020 12:09:23 -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 6C37122C9F; Mon, 17 Aug 2020 16:09:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597680562; bh=db7ks6C0AJctQO49/B+ps/2x8OHnvLRgvbnNsrSvoHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e2BJPGyy+Mq0UjHo1WHbWkNrDwVGPuOqvO7LnGpa1cv8hyt/Li83ueZZ/P51+1DQJ 8umA8CXo0GE7owILJ1KnoTk92YIqWx9mIXOLAYfYN6RxkXA2tWH4t9T729krFZJVJi Fcf9uIoe9P09VmkMzYq4MH1AJhfLmAvLs47jFgy0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?utf-8?b?VG9tw6HFoSBDaGFsb3Vwa2E=?= , Stefano Garzarella , Jens Axboe Subject: [PATCH 5.4 237/270] io_uring: set ctx sq/cq entry count earlier Date: Mon, 17 Aug 2020 17:17:18 +0200 Message-Id: <20200817143807.599814411@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143755.807583758@linuxfoundation.org> References: <20200817143755.807583758@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: Jens Axboe commit bd74048108c179cea0ff52979506164c80f29da7 upstream. If we hit an earlier error path in io_uring_create(), then we will have accounted memory, but not set ctx->{sq,cq}_entries yet. Then when the ring is torn down in error, we use those values to unaccount the memory. Ensure we set the ctx entries before we're able to hit a potential error path. Cc: stable@vger.kernel.org Reported-by: Tomáš Chaloupka Tested-by: Tomáš Chaloupka Reviewed-by: Stefano Garzarella Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -3857,6 +3857,10 @@ static int io_allocate_scq_urings(struct struct io_rings *rings; size_t size, sq_array_offset; + /* make sure these are sane, as we already accounted them */ + ctx->sq_entries = p->sq_entries; + ctx->cq_entries = p->cq_entries; + size = rings_size(p->sq_entries, p->cq_entries, &sq_array_offset); if (size == SIZE_MAX) return -EOVERFLOW; @@ -3873,8 +3877,6 @@ static int io_allocate_scq_urings(struct rings->cq_ring_entries = p->cq_entries; ctx->sq_mask = rings->sq_ring_mask; ctx->cq_mask = rings->cq_ring_mask; - ctx->sq_entries = rings->sq_ring_entries; - ctx->cq_entries = rings->cq_ring_entries; size = array_size(sizeof(struct io_uring_sqe), p->sq_entries); if (size == SIZE_MAX) {