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 AFE6A1DDCE; Tue, 16 Jul 2024 15:54:25 +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=1721145265; cv=none; b=nifJykmF+ZtMzLJI7lJ4eEpKuZoLIFS2BhIQTB0/fUHLLf8cqoTFmSpslByXr5aVoFLlSj/Y9LKd5gjxZELwhIdolCCSMPoC9tk5OENq5Qmv96sJ39AvuIFh75URVYpxgaeYncGBOGGLajquxXK5JSevsW4yXOKDyN/8Bv4COEE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721145265; c=relaxed/simple; bh=lrphtrK5ShGVTBvisC+AUhTOlWRhsCwAi95vHchpWw0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WdEqpZhidk+2JzeLpWuef60joJm4LD2V6fjDfJ+tZBeUvsvB2TPZ7XFExOnHy40iJknYkCQBKaAhTOHWrRWMt61QW5DA4KJvr0ySNjguKUd6PBgfed1uF25mVy/6NkHkeSjOjE83cpPL/oJXm7ABA5wswb7S2PCHVLKk9YvUnSs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YU2Ms/Z1; 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="YU2Ms/Z1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35D0AC116B1; Tue, 16 Jul 2024 15:54:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1721145265; bh=lrphtrK5ShGVTBvisC+AUhTOlWRhsCwAi95vHchpWw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YU2Ms/Z1URtbvEBMWbKo4jsnnMrmYRE9s5xofuQPQwsE/7Vfp38TBI0cSYC4iWz+P Y1OeAfafBDJ9WiBG3+3LDttzYyib9vlW/YIwC7Cg2j1boaOAW9V8Zab7iwJNo65Uvd dUnFDu+CLVd7uknZxxQ06IlSPPg1oMiSB16PAwqE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Waiman Long , Charan Teja Kalla , Andrew Morton , Sasha Levin Subject: [PATCH 6.1 01/96] mm: prevent derefencing NULL ptr in pfn_section_valid() Date: Tue, 16 Jul 2024 17:31:12 +0200 Message-ID: <20240716152746.574857271@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240716152746.516194097@linuxfoundation.org> References: <20240716152746.516194097@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org 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: Waiman Long [ Upstream commit 82f0b6f041fad768c28b4ad05a683065412c226e ] Commit 5ec8e8ea8b77 ("mm/sparsemem: fix race in accessing memory_section->usage") changed pfn_section_valid() to add a READ_ONCE() call around "ms->usage" to fix a race with section_deactivate() where ms->usage can be cleared. The READ_ONCE() call, by itself, is not enough to prevent NULL pointer dereference. We need to check its value before dereferencing it. Link: https://lkml.kernel.org/r/20240626001639.1350646-1-longman@redhat.com Fixes: 5ec8e8ea8b77 ("mm/sparsemem: fix race in accessing memory_section->usage") Signed-off-by: Waiman Long Cc: Charan Teja Kalla Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- include/linux/mmzone.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 93d2003091222..61906244c14d6 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1814,8 +1814,9 @@ static inline int subsection_map_index(unsigned long pfn) static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn) { int idx = subsection_map_index(pfn); + struct mem_section_usage *usage = READ_ONCE(ms->usage); - return test_bit(idx, READ_ONCE(ms->usage)->subsection_map); + return usage ? test_bit(idx, usage->subsection_map) : 0; } #else static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn) -- 2.43.0