Received: by 10.213.65.68 with SMTP id h4csp1717488imn; Mon, 19 Mar 2018 11:18:54 -0700 (PDT) X-Google-Smtp-Source: AG47ELukrSOuiiJX3+fXD2siRG7VCZlUDUrfA31bcTYZR5o6gfzbfp/wz8eurr3nJhfihR+1JTnu X-Received: by 10.98.242.6 with SMTP id m6mr11000847pfh.230.1521483534012; Mon, 19 Mar 2018 11:18:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521483533; cv=none; d=google.com; s=arc-20160816; b=jrCNuZYJY+yU19c0hkQ1mQY/w/gVWwKrftcMOO1fuVxMzu4T7N4LC0iaipGyDdnus7 9etY0uuhU7dg4XT6n1PjBLonu0YbxYbkInUWupbJOpp+XsPWQO9osvKcda8pYrv84jHv GIoMHbuFXKSeJ5ZZLckauiYweaxZtySKyvAzE70V58qXJgYtim00+vWbcaHgwEFwC5+Q uc3jsD2VGbtyUj+cvFYz8dXQu9en2ihs/nRVM5zTmM7uzDW1kXkp3l/Hiwu80/b4Iya3 HINKu73ZFt9tWSwbsmB/CZTJ2MmaxL7YDUOHPUqcixd3HV7dlZnmlY3xVcwx8ne0uUfJ sRUA== 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=hEFsK66u/qvAcu2RNzaj+6Bfl7+Y+Vs2iQK967iWSc4=; b=ydy5jJgMhURt5dNwiPhK7ktBEwppOdAyVYjVZvDQhMwYkZjBsRvxhHL0xp6/PWNX8A SBRbAeDJvnj2VKkBfQEkzQaEREbGr/lGplobRWeJKRn4+159zkrrbeWZ5EBiJUitw/Z8 jTm3dsc93oJFOe9XU6ANlgf/fVSletlwKrrof5BwHBGPp+JZj5Xa87XGMWkG+JH7ai9E bU4NmAH/sXjOswDCkdcXFbLbdhgAenmDkq5HKnGIVilwexruv27DOrXjiR5qrp3FhdDY 99fNanicKohbjKQJ4jctzssc3S9y0JbzYnw4/TxI719qQdhQ7tO+JxuqitlFWH2qzWQl YvAw== 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 f14si293972pgn.824.2018.03.19.11.18.39; Mon, 19 Mar 2018 11:18:53 -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 S969140AbeCSSRY (ORCPT + 99 others); Mon, 19 Mar 2018 14:17:24 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45476 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S969126AbeCSSRQ (ORCPT ); Mon, 19 Mar 2018 14:17: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 C912B124E; Mon, 19 Mar 2018 18:17: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.4 124/134] fs/aio: Use RCU accessors for kioctx_table->table[] Date: Mon, 19 Mar 2018 19:06:47 +0100 Message-Id: <20180319171907.175053555@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319171849.024066323@linuxfoundation.org> References: <20180319171849.024066323@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.4-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 { @@ -327,7 +327,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; @@ -651,9 +651,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, @@ -828,8 +828,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 */ @@ -874,7 +874,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++; @@ -1063,7 +1064,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;