From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90F5D63B8 for ; Mon, 20 Feb 2023 13:53:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AD5FC433D2; Mon, 20 Feb 2023 13:53:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1676901192; bh=Y/SJT7ZPzet7n6iUujN7E0T24syAivYUtJwYYNzRf1M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aQcU+Z4aCd08/YZrzYTTxhbRqAW1JGrMoUlxseMGquQCSIQkWQildhRxESYFy5cj6 t9ta61mvJW2DPpwbl/qGNGZxkwe28MpZswNfvVGYjDzJKLUzCvSEyH51QlqiksRinI IyZ8uNfPU/sSaQJmbF4C0LmEHCNiIdJfRbwLDR9I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Seth Jenkins , Jeff Moyer , Alexander Viro , Benjamin LaHaise , Jann Horn , Pavel Emelyanov , Andrew Morton Subject: [PATCH 5.15 35/83] aio: fix mremap after fork null-deref Date: Mon, 20 Feb 2023 14:36:08 +0100 Message-Id: <20230220133554.893034323@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230220133553.669025851@linuxfoundation.org> References: <20230220133553.669025851@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Seth Jenkins commit 81e9d6f8647650a7bead74c5f926e29970e834d1 upstream. 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. [jmoyer@redhat.com: fix 80 column issue] Link: https://lkml.kernel.org/r/x49sffq4nvg.fsf@segfault.boston.devel.redhat.com Fixes: e4a0d3e720e7 ("aio: Make it possible to remap aio ring") Signed-off-by: Seth Jenkins Signed-off-by: Jeff Moyer Cc: Alexander Viro Cc: Benjamin LaHaise Cc: Jann Horn Cc: Pavel Emelyanov Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- fs/aio.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/fs/aio.c +++ b/fs/aio.c @@ -334,6 +334,9 @@ static int aio_ring_mremap(struct vm_are 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; @@ -347,6 +350,7 @@ static int aio_ring_mremap(struct vm_are } } +out_unlock: rcu_read_unlock(); spin_unlock(&mm->ioctx_lock); return res;