Received: by 10.213.65.68 with SMTP id h4csp17958imn; Mon, 19 Mar 2018 18:03:52 -0700 (PDT) X-Google-Smtp-Source: AG47ELvO5Ttlqump1pndA1ZfLrqLkIi2sxjUWX3WUFrvjMhAyafHEBubOrC6fWXq6K88AHoyh48w X-Received: by 10.98.82.144 with SMTP id g138mr11777187pfb.239.1521507832526; Mon, 19 Mar 2018 18:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521507832; cv=none; d=google.com; s=arc-20160816; b=Rd3MIvHrGsCGMlRusybwHzr5Om/tnTW+p6iQQOo4qVzgjTG5kF0R++qLJ6R29rBVYg 3ZRgBtwxs1bHsPk9huimRV6lhIvQwl/CWrM6ShcdWTOu51xAqCorY11lVC8iv7drZyFO 88ejOmQbmUXcHLvHxjELja1Z1vEfbOUJoqpljXfIkRQRd9xbj6D3oTPhdk90bLlTXaIn KExLHnPz0nLaUb0i2K6O/5YpQCvhmWEntvCtEhcEoCSUHf+rCPKTRxGqkzsEN4EDgGBV dBtCiSGzHjhSYxllVPLlT6hAX60ZVmfY7XpLfcDgnfWE/pPvnJRECTdC7cxQHs9VS89g 5Qzw== 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=H6C+DUXrOiHqqaQVNIvn2CAYwe82UZ17dlhf/E7BSl0=; b=ziLRPhgeVNzQOVgSzOznFm1kWGiu4mBmZS2dtnQzT9WSrZ/vnm452qLocyIox2t2/F B45qE8biyt5xImsn0vRc7kfgk3dTX/dE0hHerSjzAdYkEZeq5H8lmdvk4J/baU4KlpGM 3v5qpWiP8Y782tR84UCsJhVxVxmiHZVcDDD43saqWcKPjj6ETBAuZXxTKyk12aWLulSl HSzoX6ekXK7AbkvAuT9GxocPTu8V92XLGHx6nmy5w6Jg9t3xS6NSEM41ud2Tx8qnZLS8 vaMje1Vz9CPl4ri+nKWqXrqm/CWVfF2tLxomatuSBQrnsAsxU/m7dITveSl/UA6//d/q Z1Xw== 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 r22si362170pfh.230.2018.03.19.18.03.38; Mon, 19 Mar 2018 18:03:52 -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 S1031971AbeCSScz (ORCPT + 99 others); Mon, 19 Mar 2018 14:32:55 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:54050 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S970343AbeCSScq (ORCPT ); Mon, 19 Mar 2018 14:32:46 -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 6BE4411CE; Mon, 19 Mar 2018 18:32:45 +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.15 27/52] fs/aio: Use RCU accessors for kioctx_table->table[] Date: Mon, 19 Mar 2018 19:08:25 +0100 Message-Id: <20180319180736.596183624@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180734.976730813@linuxfoundation.org> References: <20180319180734.976730813@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.15-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; @@ -666,9 +666,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, @@ -849,8 +849,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 */ @@ -895,7 +895,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++; @@ -1084,7 +1085,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;