Re: [PATCH v2 2/3] mm, swap: distinguish a malformed swap entry from a dying device

Barry Song <[email protected]>
Newsgroups gmane.linux.kernel,gmane.linux.kernel.mm
Message-ID <CAGsJ_4x30dhvWfDH9eqkoOMAtgzLYMBLB+Rt1gEg9Gcg==kufw@mail.gmail.com>
On Thu, Aug 13, 2026 at 6:02 PM Breno Leitao <[email protected]> wrote:
>
> get_swap_device() returns NULL for two different things: an entry whose
> type names no swap device or whose offset is past the end of one, and a
> device that swapoff is taking away. The first never becomes valid, the
> second does, and callers cannot tell them apart.
>
> Return ERR_PTR(-EIO) for the two malformed cases and keep NULL for
> swapoff. copy_nonpresent_pte() already reports -EIO for the same
> corruption on the fork path.
>
> Callers bail out on failure either way, so switch them to
> IS_ERR_OR_NULL() and clear si where the cleanup path would otherwise
> put an ERR_PTR. No functional change.
>
> Signed-off-by: Breno Leitao <[email protected]>

My gut feeling is that a corrupted PTE entry could also result in
type > 0 && type < MAX_SWAPFILES and offset < si->max.
However, that would likely lead to other serious problems later.

For this patch, I think it is reasonable to report the two obvious
corrupted PTE entries as -EIO.

Reviewed-by: Barry Song <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.