Skip to content

Commit 898f944

Browse files
jtlaytonchucklever
authored andcommitted
lockd: don't allow locking on reexported NFSv2/3
Since commit 9254c8a ("nfsd: disallow file locking and delegations for NFSv4 reexport"), file locking when reexporting an NFS mount via NFSv4 is expressly prohibited by nfsd. Do the same in lockd: Add a new nlmsvc_file_cannot_lock() helper that will test whether file locking is allowed for a given file, and return nlm_lck_denied_nolocks if it isn't. Signed-off-by: Jeff Layton <jlayton@kernel.org> Tested-by: Olga Kornievskaia <okorniev@redhat.com> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent f6dcad1 commit 898f944

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

fs/lockd/svclock.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
495495
(long long)lock->fl.fl_end,
496496
wait);
497497

498+
if (nlmsvc_file_cannot_lock(file))
499+
return nlm_lck_denied_nolocks;
500+
498501
if (!locks_can_async_lock(nlmsvc_file_file(file)->f_op)) {
499502
async_block = wait;
500503
wait = 0;
@@ -621,6 +624,9 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
621624
(long long)lock->fl.fl_start,
622625
(long long)lock->fl.fl_end);
623626

627+
if (nlmsvc_file_cannot_lock(file))
628+
return nlm_lck_denied_nolocks;
629+
624630
if (locks_in_grace(SVC_NET(rqstp))) {
625631
ret = nlm_lck_denied_grace_period;
626632
goto out;
@@ -678,6 +684,9 @@ nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)
678684
(long long)lock->fl.fl_start,
679685
(long long)lock->fl.fl_end);
680686

687+
if (nlmsvc_file_cannot_lock(file))
688+
return nlm_lck_denied_nolocks;
689+
681690
/* First, cancel any lock that might be there */
682691
nlmsvc_cancel_blocked(net, file, lock);
683692

@@ -715,6 +724,9 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *l
715724
(long long)lock->fl.fl_start,
716725
(long long)lock->fl.fl_end);
717726

727+
if (nlmsvc_file_cannot_lock(file))
728+
return nlm_lck_denied_nolocks;
729+
718730
if (locks_in_grace(net))
719731
return nlm_lck_denied_grace_period;
720732

fs/lockd/svcshare.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ nlmsvc_share_file(struct nlm_host *host, struct nlm_file *file,
3232
struct xdr_netobj *oh = &argp->lock.oh;
3333
u8 *ohdata;
3434

35+
if (nlmsvc_file_cannot_lock(file))
36+
return nlm_lck_denied_nolocks;
37+
3538
for (share = file->f_shares; share; share = share->s_next) {
3639
if (share->s_host == host && nlm_cmp_owner(share, oh))
3740
goto update;
@@ -72,6 +75,9 @@ nlmsvc_unshare_file(struct nlm_host *host, struct nlm_file *file,
7275
struct nlm_share *share, **shpp;
7376
struct xdr_netobj *oh = &argp->lock.oh;
7477

78+
if (nlmsvc_file_cannot_lock(file))
79+
return nlm_lck_denied_nolocks;
80+
7581
for (shpp = &file->f_shares; (share = *shpp) != NULL;
7682
shpp = &share->s_next) {
7783
if (share->s_host == host && nlm_cmp_owner(share, oh)) {

include/linux/lockd/lockd.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
/* XXX: a lot of this should really be under fs/lockd. */
1414

15+
#include <linux/exportfs.h>
1516
#include <linux/in.h>
1617
#include <linux/in6.h>
1718
#include <net/ipv6.h>
@@ -307,7 +308,7 @@ void nlmsvc_invalidate_all(void);
307308
int nlmsvc_unlock_all_by_sb(struct super_block *sb);
308309
int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr);
309310

310-
static inline struct file *nlmsvc_file_file(struct nlm_file *file)
311+
static inline struct file *nlmsvc_file_file(const struct nlm_file *file)
311312
{
312313
return file->f_file[O_RDONLY] ?
313314
file->f_file[O_RDONLY] : file->f_file[O_WRONLY];
@@ -318,6 +319,12 @@ static inline struct inode *nlmsvc_file_inode(struct nlm_file *file)
318319
return file_inode(nlmsvc_file_file(file));
319320
}
320321

322+
static inline bool
323+
nlmsvc_file_cannot_lock(const struct nlm_file *file)
324+
{
325+
return exportfs_cannot_lock(nlmsvc_file_file(file)->f_path.dentry->d_sb->s_export_op);
326+
}
327+
321328
static inline int __nlm_privileged_request4(const struct sockaddr *sap)
322329
{
323330
const struct sockaddr_in *sin = (struct sockaddr_in *)sap;

0 commit comments

Comments
 (0)