Re: [PATCH v2 2/3] mm, swap: distinguish a malformed swap entry from a dying device
From: Barry Song
Date: Mon Aug 17 2026 - 06:24:50 EST
On Thu, Aug 13, 2026 at 6:02 PM Breno Leitao <leitao@xxxxxxxxxx> 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 <leitao@xxxxxxxxxx>
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 <baohua@xxxxxxxxxx>