Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2658593pxa; Mon, 17 Aug 2020 15:45:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyO1okd1w61knNOS/9yqPpY5qjxhiQQdL0KZXZj/85xb6Mqp8a8M5fNwbi5P5fQ0Z/NTAx5 X-Received: by 2002:aa7:ccd5:: with SMTP id y21mr16669836edt.91.1597704337210; Mon, 17 Aug 2020 15:45:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704337; cv=none; d=google.com; s=arc-20160816; b=Sc+lHimZhTqPMokokYZfzayS59RCHT8M/m1PioY8CbMfvEDnFU9Av0GOvKRElbQV05 duO3ecG8ZgLScI7uNKeB9IL3AZ4bbKhCpdwfGdlHlC20jFBLftAda6VAFR8zNFrE6TKf zLSdnBc/VTp9nwL1lQkyXIHqBssnJBrKw94KhQBdrkWMCYzPpB2WGHFTX7Z94PseLnI5 X+r3v6166TwlbQPP2hhgatsn0Og5lI7+m5P8MKm+G/u78zpe56UvMIKOdgYDzgi+St5i nqe/qdxle2oSWxD9iPKyAJLXmvHXDDUieIMTLN8+t70kuL8QCAV9om2+8gY1wn73z3IP H+AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JUH06Q55XmZSJMx6ve5F/Wm88GvXmAsC8+mwrhOkVQw=; b=G+vLA3Ix+5LkhvINn0GUw3cmCXdt2795BaYPrOxuO7wizXweIs/qUulNudqI8A2Y0K AL993VK1JxkVHj0GFJTo2xMIjfUrJv05AM+7ngxLS4r5cAWCxWnm2/qxPfFZgqdMWXZF VAUBicCiqmqkMRUeaROvLwH4oNGVK1eo3GHM7TstFXAecolZRLFkmqx8jOdJDKxgFr0g LJUMJacuhtWu3//k1s4sp7wF7PthyAjC3Z8et36i5M6OREeJXYh1wc8iowupqats2iSV aaOJYJ92Fl1/QHYLkhQENTwcGKWodFD+GD1L3B1s7lix+yKjd7IE/jJaCtj6uzrVFBCQ 5pew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jQFSvoQh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n9si11538140edo.79.2020.08.17.15.45.12; Mon, 17 Aug 2020 15:45:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jQFSvoQh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731921AbgHQTPj (ORCPT + 99 others); Mon, 17 Aug 2020 15:15:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:48480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387464AbgHQPjv (ORCPT ); Mon, 17 Aug 2020 11:39:51 -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 00A3E23105; Mon, 17 Aug 2020 15:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678789; bh=aUOs9LCM4c8OQ2S4wj4edcrtg3pphFJSpYWD2ii3lf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jQFSvoQhZPgwHr906iCjixBCveRhoV2rwwpDfWgSfJ/3LoZYkLUFxkEHZgo6FJr90 VWeC6ZpxEPdSq7EwO97rFu3r2QJ7DhEtbhU4PBqLTxMvLXnONBwn6yQ8ZjmVui+K9+ dMGKwwnOwzDqzWo7cP2Nb2eSIT7eXMD9eMVWgyr0= 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.8 424/464] io_uring: set ctx sq/cq entry count earlier Date: Mon, 17 Aug 2020 17:16:17 +0200 Message-Id: <20200817143854.084312729@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 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 @@ -7834,6 +7834,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; @@ -7850,8 +7854,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) {