Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11787357pjo; Thu, 2 Jan 2020 14:16:42 -0800 (PST) X-Google-Smtp-Source: APXvYqxbTBFhNlZpX55+ylLDxQ3y90oOMyPpkXHJjUxiXlV68/tA0VQPl+xT0W3ZgXVUZbuBnmDI X-Received: by 2002:a05:6830:1d7b:: with SMTP id l27mr948409oti.251.1578003402360; Thu, 02 Jan 2020 14:16:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578003402; cv=none; d=google.com; s=arc-20160816; b=oS8AoyJl5x5FpQX9jwlVlwmiAoyd5CeQLcmlPVJBBJMWiD0Brhz/dg5qHmIgAOc7Ek mECEgNMnA3gY7Z/BedJfMEAdQc8wM5haKwMQSJ/9CgcDRcI5Q4RGFQvEpWfkBXabFD56 d1EGORh9CQgdb1JinxNAOTKwwtT0NKf7APwNxpxprf8ngIy7ywoxKgQx4+CdfP6VdoqL 0RwQaRDLhQqVI7mj5W5MrJlUBxPn9QGtKBi/BVHPRaq/TCRf7ETGy7HNTjljkz35CnR4 +uWgIiKkpNhZxrn57ovvaWB76X/Ckr3ULYgF6t9p5P/y8uKVdah5tupfpi1sXO0v11PG w6+A== 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=GlhadllJlTmySMHTBt5L5daRDvAiaZ/jEown46XJPzc=; b=tGpfR4z0YBbCxdfAySD54g599pjM/aJOFBc15ky0YrNTxmuQvh7X59ws9ER1LbexVe mt8ElqpaqYJ+QNPDEUbKfCFYeEAj3viYqkzP6N+Kiw2KUok6x+eZwN/gQFuYlOV6z5Kf TgXFdBakEdcZUOUD5W/qGol62zpmkVNtJ5wAdaRy0J3mwOn/YXlnzcrHqMjBEJfOYNoc t4fkVE21sips0A5mqSZT4Y31HnzjftP0h4SXwBrqh1XRXWRiaRxip1XV90J+dB6ry3HL AmLNj7NaWKeYSepwrV3JagvRPc33atMDAiH1c7WJ6T5K/7ntUHKCE2aZK7IJy61IS3ek 1BSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g0poRwov; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p21si20400835otk.162.2020.01.02.14.16.29; Thu, 02 Jan 2020 14:16:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g0poRwov; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727228AbgABWP1 (ORCPT + 99 others); Thu, 2 Jan 2020 17:15:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:56134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727753AbgABWPV (ORCPT ); Thu, 2 Jan 2020 17:15:21 -0500 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 42D2D2253D; Thu, 2 Jan 2020 22:15:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003320; bh=bf552ruxuUI7QMhE+xOcCycft/fZFhLHYKX/xrzuPmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g0poRwovI7Yk+FB+le99PAE/5iGkyNaerp0d1Gqc4zcaRPGZYDKanwZtiTS7DJZa+ gRaOGvvqp3jqnuBuSEqIYevLT1eiX4G/wMeXHYNdJcMYwe+roodHWU2rxFF6FOek5m 2oMJR1jfcJF1viz5AeBE5bwIMvT3jinfQLdjBrSk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+0d818c0d39399188f393@syzkaller.appspotmail.com, Jens Axboe , Sasha Levin Subject: [PATCH 5.4 111/191] io_uring: io_allocate_scq_urings() should return a sane state Date: Thu, 2 Jan 2020 23:06:33 +0100 Message-Id: <20200102215841.790190941@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102215829.911231638@linuxfoundation.org> References: <20200102215829.911231638@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 [ Upstream commit eb065d301e8c83643367bdb0898becc364046bda ] We currently rely on the ring destroy on cleaning things up in case of failure, but io_allocate_scq_urings() can leave things half initialized if only parts of it fails. Be nice and return with either everything setup in success, or return an error with things nicely cleaned up. Reported-by: syzbot+0d818c0d39399188f393@syzkaller.appspotmail.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index a340147387ec..74e786578c77 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -3773,12 +3773,18 @@ static int io_allocate_scq_urings(struct io_ring_ctx *ctx, ctx->cq_entries = rings->cq_ring_entries; size = array_size(sizeof(struct io_uring_sqe), p->sq_entries); - if (size == SIZE_MAX) + if (size == SIZE_MAX) { + io_mem_free(ctx->rings); + ctx->rings = NULL; return -EOVERFLOW; + } ctx->sq_sqes = io_mem_alloc(size); - if (!ctx->sq_sqes) + if (!ctx->sq_sqes) { + io_mem_free(ctx->rings); + ctx->rings = NULL; return -ENOMEM; + } return 0; } -- 2.20.1