Received: by 10.213.65.68 with SMTP id h4csp1724678imn; Mon, 19 Mar 2018 11:30:17 -0700 (PDT) X-Google-Smtp-Source: AG47ELtrBSYSkwcgj6jBLVkJdLbgN7DPkFcKw1pcKFavkSVNB2Tme/2JCqW48R69BGvh88u5rCDq X-Received: by 10.99.102.132 with SMTP id a126mr9636797pgc.385.1521484217223; Mon, 19 Mar 2018 11:30:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521484217; cv=none; d=google.com; s=arc-20160816; b=OUg4wLT+P88ASvqq/X+zrPQJYeWam/9sLirUo2NOrxh6o+s2yoOMPnZlY24dYkxhjs TgSkkvg0ZUkZv4/ijJCshLUIqBaH0QMxkCaLa3CkH4NgTEO6fgpJZFBV+RGXpJJF64w2 Vs4MmZjrTdxDDIl673KZY4I4F0ewV5Cn3pfv3KjiyfB16ksCIHVFxaolzVAuWTwFLHqG BAa+APnzBvIz+U6fQNHA1IKr93NJ4NCZgLGEEuZjOppbF5iZhnUCYCZB+uxq4jpuwFhT eXJidgeDblpEgkKWg/rcYzGjsppE23IK1O0QQ9r9EnYdb61UjTQEe6N0IpiWMC0BuFg8 nR7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=jo3WKLPq9X/WOAUfENi+zNiTCf4baiqVqcE5ZpvmRKw=; b=XdimNKfKrFO9AZq4LU2T9t7zR18CexpNksdJYzXB0ozBTJlLOB/zoEiU55Vluif7Pq N5EBNOmGu1W7UQ8kDXn5gfWB6+p5g731VCFyKoIuTMkw9PTqDXAM+aT0bvekUxlHeav4 LKqUN4wMit50q58aPQkLJEzOtzNY7DXn9S4qtNPuF/dn4THXiIsUkd5WYxV+b5H9EYua EngE3ztbPbeZRjLUImZY+DbWoGb6K3m282k/bsRc+FUubySzp3F2EQtRTtGmkTtl2ZeB wa/DPEP0xs6JRqOOelluOoVUfz5YrRYiVSYKkjLX6PwNsQM9Zhu8zSopeBOuBrFBqY9a i20Q== ARC-Authentication-Results: i=1; mx.google.com; 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 k7si328127pgo.509.2018.03.19.11.30.02; Mon, 19 Mar 2018 11:30:17 -0700 (PDT) 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; 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 S970118AbeCSS2U (ORCPT + 99 others); Mon, 19 Mar 2018 14:28:20 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51564 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031734AbeCSS2Q (ORCPT ); Mon, 19 Mar 2018 14:28:16 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0010812B1; Mon, 19 Mar 2018 18:28:15 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tejun Heo , Jann Horn , Benjamin LaHaise , Linus Torvalds Subject: [PATCH 4.9 231/241] fs/aio: Use RCU accessors for kioctx_table->table[] Date: Mon, 19 Mar 2018 19:08:16 +0100 Message-Id: <20180319180800.735068986@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tejun Heo commit d0264c01e7587001a8c4608a5d1818dba9a4c11a upstream. While converting ioctx index from a list to a table, db446a08c23d ("aio: convert the ioctx list to table lookup v3") missed tagging kioctx_table->table[] as an array of RCU pointers and using the appropriate RCU accessors. This introduces a small window in the lookup path where init and access may race. Mark kioctx_table->table[] with __rcu and use the approriate RCU accessors when using the field. Signed-off-by: Tejun Heo Reported-by: Jann Horn Fixes: db446a08c23d ("aio: convert the ioctx list to table lookup v3") Cc: Benjamin LaHaise Cc: Linus Torvalds Cc: stable@vger.kernel.org # v3.12+ Signed-off-by: Greg Kroah-Hartman --- fs/aio.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) --- a/fs/aio.c +++ b/fs/aio.c @@ -68,9 +68,9 @@ struct aio_ring { #define AIO_RING_PAGES 8 struct kioctx_table { - struct rcu_head rcu; - unsigned nr; - struct kioctx *table[]; + struct rcu_head rcu; + unsigned nr; + struct kioctx __rcu *table[]; }; struct kioctx_cpu { @@ -330,7 +330,7 @@ static int aio_ring_mremap(struct vm_are for (i = 0; i < table->nr; i++) { struct kioctx *ctx; - ctx = table->table[i]; + ctx = rcu_dereference(table->table[i]); if (ctx && ctx->aio_ring_file == file) { if (!atomic_read(&ctx->dead)) { ctx->user_id = ctx->mmap_base = vma->vm_start; @@ -659,9 +659,9 @@ static int ioctx_add_table(struct kioctx while (1) { if (table) for (i = 0; i < table->nr; i++) - if (!table->table[i]) { + if (!rcu_access_pointer(table->table[i])) { ctx->id = i; - table->table[i] = ctx; + rcu_assign_pointer(table->table[i], ctx); spin_unlock(&mm->ioctx_lock); /* While kioctx setup is in progress, @@ -836,8 +836,8 @@ static int kill_ioctx(struct mm_struct * } table = rcu_dereference_raw(mm->ioctx_table); - WARN_ON(ctx != table->table[ctx->id]); - table->table[ctx->id] = NULL; + WARN_ON(ctx != rcu_access_pointer(table->table[ctx->id])); + RCU_INIT_POINTER(table->table[ctx->id], NULL); spin_unlock(&mm->ioctx_lock); /* free_ioctx_reqs() will do the necessary RCU synchronization */ @@ -882,7 +882,8 @@ void exit_aio(struct mm_struct *mm) skipped = 0; for (i = 0; i < table->nr; ++i) { - struct kioctx *ctx = table->table[i]; + struct kioctx *ctx = + rcu_dereference_protected(table->table[i], true); if (!ctx) { skipped++; @@ -1071,7 +1072,7 @@ static struct kioctx *lookup_ioctx(unsig if (!table || id >= table->nr) goto out; - ctx = table->table[id]; + ctx = rcu_dereference(table->table[id]); if (ctx && ctx->user_id == ctx_id) { percpu_ref_get(&ctx->users); ret = ctx;