| Message ID | 20260512053625.2950900-5-hch@lst.de |
|---|---|
| State | Not Applicable |
| Headers | show |
| Series | [01/12] swap: remove the maxpages variable in sys_swapon | expand |
On 5/12/26 14:35, Christoph Hellwig wrote: > Various swap code assumes it runs either on a block device or on a > regular file. Make this restriction explicit using checks right > after opening the file. > > Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
On Tue, May 12, 2026 at 07:35:20AM +0200, Christoph Hellwig wrote: > Various swap code assumes it runs either on a block device or on a > regular file. Make this restriction explicit using checks right > after opening the file. > > Signed-off-by: Christoph Hellwig <hch@lst.de> Makes sense to me. Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> --D > --- > mm/swapfile.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/mm/swapfile.c b/mm/swapfile.c > index a183c9c95695..651c1b59ff9f 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -3515,6 +3515,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) > error = -ENOENT; > goto bad_swap_unlock_inode; > } > + if (!S_ISBLK(inode->i_mode) && !S_ISREG(inode->i_mode)) { > + error = -EINVAL; > + goto bad_swap_unlock_inode; > + } > if (IS_SWAPFILE(inode)) { > error = -EBUSY; > goto bad_swap_unlock_inode; > -- > 2.53.0 > >
On Mon, May 11, 2026 at 10:37 PM Christoph Hellwig <hch@lst.de> wrote: > > Various swap code assumes it runs either on a block device or on a > regular file. Make this restriction explicit using checks right > after opening the file. > > Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Chris Li <chrisl@kernel.org> Chris
diff --git a/mm/swapfile.c b/mm/swapfile.c index a183c9c95695..651c1b59ff9f 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3515,6 +3515,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) error = -ENOENT; goto bad_swap_unlock_inode; } + if (!S_ISBLK(inode->i_mode) && !S_ISREG(inode->i_mode)) { + error = -EINVAL; + goto bad_swap_unlock_inode; + } if (IS_SWAPFILE(inode)) { error = -EBUSY; goto bad_swap_unlock_inode;
Various swap code assumes it runs either on a block device or on a regular file. Make this restriction explicit using checks right after opening the file. Signed-off-by: Christoph Hellwig <hch@lst.de> --- mm/swapfile.c | 4 ++++ 1 file changed, 4 insertions(+)