Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C327C38142 for ; Tue, 31 Jan 2023 17:23:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232036AbjAaRXc (ORCPT ); Tue, 31 Jan 2023 12:23:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229651AbjAaRX3 (ORCPT ); Tue, 31 Jan 2023 12:23:29 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7BA64A225 for ; Tue, 31 Jan 2023 09:22:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675185722; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=O6xc7yUQ+r4mGl3gQ8IQAPstO5OTYvuNZtxO7PVTBMY=; b=UYbJOAqbmXuhSFgMOHaU6Znjymi4klSOyDXp4shhNgNldphg8Ux21jHDxY0jUSKq5F+xXl aClFyhPmerFwhC7DgnvAOGEYzaOglVB/5a0jUIviI4Rg79P0+L/uK/vfEvK65gqz3V/7/a /vks0Jh84lK60nBJ9WHIf8gbHE2nyZY= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-224-pbV9lm5-NOmj2ZG9wDkk0Q-1; Tue, 31 Jan 2023 12:21:57 -0500 X-MC-Unique: pbV9lm5-NOmj2ZG9wDkk0Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AFF893814945; Tue, 31 Jan 2023 17:21:56 +0000 (UTC) Received: from segfault.boston.devel.redhat.com (segfault.boston.devel.redhat.com [10.19.60.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 593D7112132C; Tue, 31 Jan 2023 17:21:56 +0000 (UTC) From: Jeff Moyer To: Seth Jenkins , Alexander Viro , Benjamin LaHaise , Andrew Morton Cc: linux-fsdevel@vger.kernel.org, linux-aio@kvack.org, linux-kernel@vger.kernel.org, Jann Horn , Pavel Emelyanov , stable@vger.kernel.org Subject: [PATCH][v2] aio: fix mremap after fork null-deref X-PGP-KeyID: 1F78E1B4 X-PGP-CertKey: F6FE 280D 8293 F72C 65FD 5A58 1FF8 A7CA 1F78 E1B4 Date: Tue, 31 Jan 2023 12:25:55 -0500 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Seth Jenkins Commit e4a0d3e720e7 ("aio: Make it possible to remap aio ring") introduced a null-deref if mremap is called on an old aio mapping after fork as mm->ioctx_table will be set to NULL. Fixes: e4a0d3e720e7 ("aio: Make it possible to remap aio ring") Cc: stable@vger.kernel.org Signed-off-by: Seth Jenkins [JEM: fixed 80 column issue] Signed-off-by: Jeff Moyer --- This passes the libaio test harness and fstests ./check -g aio. I also wrote a targeted test program and verified the issue was fixed. fs/aio.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/aio.c b/fs/aio.c index 562916d85cba..e85ba0b77f59 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -361,6 +361,9 @@ static int aio_ring_mremap(struct vm_area_struct *vma) spin_lock(&mm->ioctx_lock); rcu_read_lock(); table = rcu_dereference(mm->ioctx_table); + if (!table) + goto out_unlock; + for (i = 0; i < table->nr; i++) { struct kioctx *ctx; @@ -374,6 +377,7 @@ static int aio_ring_mremap(struct vm_area_struct *vma) } } +out_unlock: rcu_read_unlock(); spin_unlock(&mm->ioctx_lock); return res;