From mboxrd@z Thu Jan 1 00:00:00 1970 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=unavailable 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 74AEAC433DF for ; Mon, 17 Aug 2020 17:04:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 418282067C for ; Mon, 17 Aug 2020 17:04:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597683898; bh=db7ks6C0AJctQO49/B+ps/2x8OHnvLRgvbnNsrSvoHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=KBlTG/tkt9bAcD1jQNJ4KqYgHC2nHFZ8a5qX1sQdei+C+GS6fjnG4v4NUgzYhyfcU t01I14g80Wfz6ZCt+GWUMI/3WvO/pGdBRb8bcQVuE8tcZlmt2WJOh6zfYpYqU+w3UA pFsKZtWBBTTqywOnjfxry5UtaRcEuVRH2JKT5c9o= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731400AbgHQREy (ORCPT ); Mon, 17 Aug 2020 13:04:54 -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?q?Tom=C3=A1=C5=A1=20Chaloupka?= , 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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) {