2021-08-27 15:17:05

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] Don't block writes to swap-files with ETXTBSY.

On Thu, Aug 26, 2021 at 09:57:39AM +1000, NeilBrown wrote:
>
> Commit dc617f29dbe5 ("vfs: don't allow writes to swap files")
> broke swap-over-NFS as it introduced an ETXTBSY error when NFS tries to
> swap-out using ->direct_IO().
>
> There is no sound justification for this error. File permissions are
> sufficient to stop non-root users from writing to a swap file, and root
> must always be cautious not to do anything dangerous.
>
> These checks effectively provide a mandatory write lock on swap, and
> mandatory locks are not supported in Linux.
>
> So remove all the checks that return ETXTBSY when attempts are made to
> write to swap.

Swap files are not just any files and do need a mandatory write lock
as they are part of the kernel VM and writing to them will mess up
the kernel badly. David Howells actually has sent various patches
to fix swap over NFS in the last weeks.


2021-08-27 23:10:36

by NeilBrown

[permalink] [raw]
Subject: Re: [PATCH] Don't block writes to swap-files with ETXTBSY.

On Sat, 28 Aug 2021, Christoph Hellwig wrote:
> On Thu, Aug 26, 2021 at 09:57:39AM +1000, NeilBrown wrote:
> >
> > Commit dc617f29dbe5 ("vfs: don't allow writes to swap files")
> > broke swap-over-NFS as it introduced an ETXTBSY error when NFS tries to
> > swap-out using ->direct_IO().
> >
> > There is no sound justification for this error. File permissions are
> > sufficient to stop non-root users from writing to a swap file, and root
> > must always be cautious not to do anything dangerous.
> >
> > These checks effectively provide a mandatory write lock on swap, and
> > mandatory locks are not supported in Linux.
> >
> > So remove all the checks that return ETXTBSY when attempts are made to
> > write to swap.
>
> Swap files are not just any files and do need a mandatory write lock
> as they are part of the kernel VM and writing to them will mess up
> the kernel badly. David Howells actually has sent various patches
> to fix swap over NFS in the last weeks.
>
>
There are lots of different things root can do which will mess up the
kernel badly. The backing-store can still be changed through some other
means.
Do you have a particular threat or risk scenario other than "root might
get careless"?

Yes, I've seen David's patches. I posted this one because I think the
original patch which broke swap-over-NFS was not just unfortunate, but
wrong. Permissions are how we protect files, not ETXTBSY.

NeilBrown

2021-08-28 07:11:05

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] Don't block writes to swap-files with ETXTBSY.

On Sat, Aug 28, 2021 at 09:10:15AM +1000, NeilBrown wrote:
> There are lots of different things root can do which will mess up the
> kernel badly. The backing-store can still be changed through some other
> means.
> Do you have a particular threat or risk scenario other than "root might
> get careless"?

No, it is just that scenario. But one that is much easier to trigger
than more convoluted ways for a root user to trigger damage through
device files, and one that can't be prevented through LSMs or the
capability system.

2021-09-02 04:22:11

by Wang Yugui

[permalink] [raw]
Subject: Re: [PATCH] Don't block writes to swap-files with ETXTBSY.

Hi,

# drop [email protected], [email protected], [email protected], [email protected]

A Question about ETXTBSY of nfs.
# I tried google/bing, but yet no good info is found.

test case:
/ssd is a nfs directory
kernel: 5.10.61, 5.4.106 and more

1, on Node1:
[root@T630 ~]# echo -e '#!/bin/bash\necho hello' >/ssd/a.sh
[root@T630 ~]# chmod a+x /ssd/a.sh

2, on Node2:
[root@T640 ~]# /ssd/a.sh
-bash: /ssd/a.sh: /bin/bash: bad interpreter: Text file busy
[root@T640 ~]# bash /ssd/a.sh
hello
[root@T640 ~]# /ssd/a.sh
-bash: /ssd/a.sh: /bin/bash: bad interpreter: Text file busy

Is there any way(flush, sync) to avoid this ETXTBSY error(Text file busy)?

Best Regards
Wang Yugui ([email protected])
2021/09/02

> On Thu, Aug 26, 2021 at 09:57:39AM +1000, NeilBrown wrote:
> >
> > Commit dc617f29dbe5 ("vfs: don't allow writes to swap files")
> > broke swap-over-NFS as it introduced an ETXTBSY error when NFS tries to
> > swap-out using ->direct_IO().
> >
> > There is no sound justification for this error. File permissions are
> > sufficient to stop non-root users from writing to a swap file, and root
> > must always be cautious not to do anything dangerous.
> >
> > These checks effectively provide a mandatory write lock on swap, and
> > mandatory locks are not supported in Linux.
> >
> > So remove all the checks that return ETXTBSY when attempts are made to
> > write to swap.
>
> Swap files are not just any files and do need a mandatory write lock
> as they are part of the kernel VM and writing to them will mess up
> the kernel badly. David Howells actually has sent various patches
> to fix swap over NFS in the last weeks.