Skip to content

nfsd/sunrpc: cleanup resource with sync mode

Yang Erkun linux-nfs netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest4 patches 6 repliesIn review

Changes in v2 from the cover letter

1. do not change cache_check, instead add cache_check_rcu and use it in c_show/e_show
2. the first patch has been applied

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4SUNRPC: introduce cache_check_rcu to help check in rcu contextinclude/linux/sunrpc/cache.h net/sunrpc/cache.c+28 -150 replies
2/4nfsd: no need get cache ref when protected by rcufs/nfsd/export.c+1 -50 replies
3/4SUNRPC: no need get cache ref when protected by rcunet/sunrpc/cache.c+3 -90 replies
4/4nfsd: fix UAF when access ex_uuid or ex_statsfs/nfsd/export.c+14 -53 replies

Reviews trailers per patch

1 of 4 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchNeilBrownJeff Layton
SeriesR-b
1/4
2/4
3/4
4/4R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/4] nfsd/sunrpc: cleanup resource with sync mode

After f8c989a0c89a ("nfsd: release svc_expkey/svc_export with rcu_work"), svc_export_put/expkey_put will call path_put with async mode. This can lead some unexpected failure:

mkdir /mnt/sda
mkfs.xfs -f /dev/sda
echo "/ *(rw,no_root_squash,fsid=0)" > /etc/exports echo "/mnt *(rw,no_root_squash,fsid=1)" >> /etc/exports exportfs -ra
service nfs-server start
mount -t nfs -o vers=4.0 127.0.0.1:/mnt /mnt1 mount /dev/sda /mnt/sda
touch /mnt1/sda/file
exportfs -r
umount /mnt/sda # failed unexcepted

The touch above will finally call nfsd_cross_mnt, add refcount to mount, and then add cache_head. Before this commit, exportfs -r will call cache_flush to cleanup all cache_head, and path_put in svc_export_put/expkey_put will be finished with sync mode. So, the latter umount will always success. However, after this commit, path_put will be called with async mode, the latter umount may failed, and if we add some delay, umount will success too. Personally I think this bug and should be fixed. We first revert before bugfix patch, and then fix the original bug with a different way.

v1->v2:

1. do not change cache_check, instead add cache_check_rcu and use it in c_show/e_show
2. the first patch has been applied

Yang Erkun (4):
SUNRPC: introduce cache_check_rcu to help check in rcu context
nfsd: no need get cache ref when protected by rcu
SUNRPC: no need get cache ref when protected by rcu
nfsd: fix UAF when access ex_uuid or ex_stats

 fs/nfsd/export.c             | 25 ++++++++++-------
 include/linux/sunrpc/cache.h |  2 ++
 net/sunrpc/cache.c           | 53 ++++++++++++++++++++----------------
 3 files changed, 46 insertions(+), 34 deletions(-)
Signature · 1 line
2.46.1