Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1985268pxx; Sat, 31 Oct 2020 04:52:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6LUYzx+F2rXjwfcx/hOPL/GN7hzWXZ6gRCW93se0J/Ij22tArbsAzvSDNpdvuU/roZ85F X-Received: by 2002:a17:906:f752:: with SMTP id jp18mr5280992ejb.331.1604145173011; Sat, 31 Oct 2020 04:52:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604145173; cv=none; d=google.com; s=arc-20160816; b=vZNtYlKw6NA16H/BruxbBQJqJ/Z+0FqDTR2FxoR7TcgqCbspx4L/wUSsEA+ttwjnkm LBjAWIRtXOU+xB4oEu8JYFF+VhjOUxEhbjMnLYmtqhZDjjtg+/CIUtXhHX/TzAFGue4A hIw0q1VLGIZfgAMQ1Zr4puV74lBXGYMOb39YJACEpDkLI4kvDqOP98j0TjrBAJ0WCLqg YP/ihtRb2FnFYrRopsAGjWFlKiEixfD33qdJkSPxVMmYqTmpTyIIn/zGTizzOzd652dE PHOoU4+HTMzLJQv7HmTHRu+Ih/p7dnzUkFVqI0j+U1m+YmrgaKIFiN2KkEtJciUeqMqX eQag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=h+tIGRXzzNA9tiFnrQ6CqdgExRg/OAJ1jk5r9L3C5l0=; b=AjIUr/2w4gaA1DTtZ9yFBtyY/WyPUwzjPkNQfbqdFJK1JE2aTQKyCznv5gRhX2+CaE u6GQ2p81dF0F6ERt3rNZCET6O6UBw9jmXmP3XnI7zQmVnAZwyLnAEFU+D8kPlQ8eW487 qqF50zFZgKk1fxVqPV32PFzplRyQNKZJ9MMF9MoTSddQAJaZnXf3/Kf2xALCqXb8YIpE x48CxnYomfk12F9/8Rx8Z27M1J2IimSdNaWxUQJgHUoi/zGmgokwAfcPiRf2bHZFx/lh 5Bw74p2ynHK3PotWGiq17sQmRPPa66Rcs95pJ+DSKXETw+JhGpFF925F00kk+OUU/AWl gt3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rWJUtd+E; 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 gt24si6401013ejb.90.2020.10.31.04.52.30; Sat, 31 Oct 2020 04:52:52 -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=rWJUtd+E; 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 S1728046AbgJaLst (ORCPT + 99 others); Sat, 31 Oct 2020 07:48:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:43580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727186AbgJaLnd (ORCPT ); Sat, 31 Oct 2020 07:43:33 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 A1AE020731; Sat, 31 Oct 2020 11:43:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604144613; bh=0f+liBFOx5aRkrtaNJZpuxJqaIdXm7vvq9XZUoYNoyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rWJUtd+E/S+QRBZsCRCX8CW6T8cQrsd2xzJO1yaOA+4jRpXqnPHUnkfSunjKVbiqB NbsquEBexVPoqk4NI2opJNRK46zic2vG/QQEvPQZ7cLTjdS/ygbEaDWLMfqRKc8gB4 Zyp1G5qlqK+4DcXNhdF4+tS2XZfZkA2FgQmo56zw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Matthew Wilcox (Oracle)" , Jens Axboe Subject: [PATCH 5.9 15/74] io_uring: Fix XArray usage in io_uring_add_task_file Date: Sat, 31 Oct 2020 12:35:57 +0100 Message-Id: <20201031113500.781089648@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201031113500.031279088@linuxfoundation.org> References: <20201031113500.031279088@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Matthew Wilcox (Oracle)" commit 236434c3438c4da3dfbd6aeeab807577b85e951a upstream. The xas_store() wasn't paired with an xas_nomem() loop, so if it couldn't allocate memory using GFP_NOWAIT, it would leak the reference to the file descriptor. Also the node pointed to by the xas could be freed between the call to xas_load() under the rcu_read_lock() and the acquisition of the xa_lock. It's easier to just use the normal xa_load/xa_store interface here. Signed-off-by: Matthew Wilcox (Oracle) [axboe: fix missing assign after alloc, cur_uring -> tctx rename] Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -8336,27 +8336,24 @@ static void io_uring_cancel_task_request */ static int io_uring_add_task_file(struct file *file) { - if (unlikely(!current->io_uring)) { + struct io_uring_task *tctx = current->io_uring; + + if (unlikely(!tctx)) { int ret; ret = io_uring_alloc_task_context(current); if (unlikely(ret)) return ret; + tctx = current->io_uring; } - if (current->io_uring->last != file) { - XA_STATE(xas, ¤t->io_uring->xa, (unsigned long) file); - void *old; + if (tctx->last != file) { + void *old = xa_load(&tctx->xa, (unsigned long)file); - rcu_read_lock(); - old = xas_load(&xas); - if (old != file) { + if (!old) { get_file(file); - xas_lock(&xas); - xas_store(&xas, file); - xas_unlock(&xas); + xa_store(&tctx->xa, (unsigned long)file, file, GFP_KERNEL); } - rcu_read_unlock(); - current->io_uring->last = file; + tctx->last = file; } return 0;