linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: gaoxu <gaoxu2@honor.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Suren Baghdasaryan" <surenb@google.com>,
	Barry Song <21cnbao@gmail.com>,
	yipengxiang <yipengxiang@honor.com>,
	Hugh Dickins <hughd@google.com>, Chris Li <chrisl@kernel.org>
Subject: Re: [PATCH] mm: Fix possible NULL pointer dereference in __swap_duplicate
Date: Wed, 12 Feb 2025 16:18:20 -0800	[thread overview]
Message-ID: <20250212161820.4fda79a3333d2345b60cef72@linux-foundation.org> (raw)
In-Reply-To: <44655569e3a1419f800952004f07e714@honor.com>

On Wed, 12 Feb 2025 03:13:46 +0000 gaoxu <gaoxu2@honor.com> wrote:

> swp_swap_info() may return null; it is necessary to check the return value
> to avoid NULL pointer dereference. The code for other calls to
> swp_swap_info() includes checks, and __swap_duplicate() should also
> include checks.

Actually very few of the swp_swap_info() callers check for a NULL return.

> The reason why swp_swap_info() returns NULL is unclear; it may be due to
> CPU cache issues or DDR bit flips.

Quite possibly it's a kernel bug.

> The probability of this issue is very
> small, and the stack info we encountered is as follows:
> Unable to handle kernel NULL pointer dereference at virtual address
> 0000000000000058
>
> ...
>
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -3521,6 +3521,8 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage, int nr)
>  	int err, i;
>  
>  	si = swp_swap_info(entry);
> +	if (unlikely(!si))
> +		return -EINVAL;
>  
>  	offset = swp_offset(entry);
>  	VM_WARN_ON(nr > SWAPFILE_CLUSTER - offset % SWAPFILE_CLUSTER);

OK, I guess avoiding the crash is good.  But please let's include a
WARN so that we can perhaps fix the bug, if one is there.



  reply	other threads:[~2025-02-13  0:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12  3:13 gaoxu
2025-02-13  0:18 ` Andrew Morton [this message]
2025-02-13 13:08   ` 回复: " gaoxu
2025-02-13 23:35     ` Yosry Ahmed
2025-02-14 10:04       ` 回复: " gaoxu
2025-02-13  1:41 ` Nhat Pham
2025-02-13  8:51   ` 回复: " gaoxu
2025-02-13 23:07     ` Barry Song
2025-02-14 10:00       ` 回复: " gaoxu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250212161820.4fda79a3333d2345b60cef72@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=21cnbao@gmail.com \
    --cc=chrisl@kernel.org \
    --cc=gaoxu2@honor.com \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=surenb@google.com \
    --cc=yipengxiang@honor.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox