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 ADFCC2AF19; Thu, 13 Jun 2024 12:47:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718282869; cv=none; b=tGDS9aUyPsfVP5fBK8fCRUzumZyZoRlYZ8kwIoFiqagPuinzCi4JuGoWfcqWrGZ4vLy6XBpb2oSaqw08DGlMIToA0dx+3vQxmgrfNGODl2Cz1X9K6iIhNcT58okDvw6Bsdo/r8GcKKTN0MdcCK2S/4Gq20738Q5jrYZlCaeYm8g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718282869; c=relaxed/simple; bh=t2ZZJOXi+5ZBZLanynCz2AWFGfiopqFPGmCnnrr+Oeo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=usrc+FUTuxK6og2CCEqidMgJ7iao/EKBsTELcCtHmbv9R3aDrtuEfcOaEJaT9dWqCLRegG1+79tYAXt+iAn5JPRCyIinZz7Ts5k51DjtQcIpsUUB8JIfttIHSbEEOEhsrVZTz9buVPCTLsNzDcwFW4O6B8P83EIKp3xpx5fIPBE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=evdTWFu7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="evdTWFu7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2308DC4AF1A; Thu, 13 Jun 2024 12:47:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1718282869; bh=t2ZZJOXi+5ZBZLanynCz2AWFGfiopqFPGmCnnrr+Oeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=evdTWFu7Ni4tUk99ydLod7pk5V5UQhigW9KMWuPWXVy11cFYhPFpSwuzTXHAoBZxI tIJ1cZFQWOv7ApohFW7zDhrWBJrJlOCFpl2o4zQXY/PO9JznwpiNyuKtZiyvXAZKnc 4Ns983jkG3XpO/NmXvnQSo/VjByLO7YYmlt7np1c= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Liam R. Howlett" , Marius Fleischer , Sidhartha Kumar , Andrew Morton Subject: [PATCH 6.1 05/85] maple_tree: fix mas_empty_area_rev() null pointer dereference Date: Thu, 13 Jun 2024 13:35:03 +0200 Message-ID: <20240613113214.346521925@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240613113214.134806994@linuxfoundation.org> References: <20240613113214.134806994@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Liam R. Howlett commit 955a923d2809803980ff574270f81510112be9cf upstream. Currently the code calls mas_start() followed by mas_data_end() if the maple state is MA_START, but mas_start() may return with the maple state node == NULL. This will lead to a null pointer dereference when checking information in the NULL node, which is done in mas_data_end(). Avoid setting the offset if there is no node by waiting until after the maple state is checked for an empty or single entry state. A user could trigger the events to cause a kernel oops by unmapping all vmas to produce an empty maple tree, then mapping a vma that would cause the scenario described above. Link: https://lkml.kernel.org/r/20240422203349.2418465-1-Liam.Howlett@oracle.com Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Liam R. Howlett Reported-by: Marius Fleischer Closes: https://lore.kernel.org/lkml/CAJg=8jyuSxDL6XvqEXY_66M20psRK2J53oBTP+fjV5xpW2-R6w@mail.gmail.com/ Link: https://lore.kernel.org/lkml/CAJg=8jyuSxDL6XvqEXY_66M20psRK2J53oBTP+fjV5xpW2-R6w@mail.gmail.com/ Tested-by: Marius Fleischer Tested-by: Sidhartha Kumar Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- lib/maple_tree.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5368,18 +5368,18 @@ int mas_empty_area_rev(struct ma_state * if (min >= max) return -EINVAL; - if (mas_is_start(mas)) { + if (mas_is_start(mas)) mas_start(mas); - mas->offset = mas_data_end(mas); - } else if (mas->offset >= 2) { - mas->offset -= 2; - } else if (!mas_rewind_node(mas)) { + else if ((mas->offset < 2) && (!mas_rewind_node(mas))) return -EBUSY; - } - /* Empty set. */ - if (mas_is_none(mas) || mas_is_ptr(mas)) + if (unlikely(mas_is_none(mas) || mas_is_ptr(mas))) return mas_sparse_area(mas, min, max, size, false); + else if (mas->offset >= 2) + mas->offset -= 2; + else + mas->offset = mas_data_end(mas); + /* The start of the window can only be within these values. */ mas->index = min;