mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
Merge tag 'nfsd-7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux
Pull nfsd updates from Chuck Lever: - filehandle signing to defend against filehandle-guessing attacks (Benjamin Coddington) The server now appends a SipHash-2-4 MAC to each filehandle when the new "sign_fh" export option is enabled. NFSD then verifies filehandles received from clients against the expected MAC; mismatches return NFS error STALE - convert the entire NLMv4 server-side XDR layer from hand-written C to xdrgen-generated code, spanning roughly thirty patches (Chuck Lever) XDR functions are generally boilerplate code and are easy to get wrong. The goals of this conversion are improved memory safety, lower maintenance burden, and groundwork for eventual Rust code generation for these functions. - improve pNFS block/SCSI layout robustness with two related changes (Dai Ngo) SCSI persistent reservation fencing is now tracked per client and per device via an xarray, to avoid both redundant preempt operations on devices already fenced and a potential NFSD deadlock when all nfsd threads are waiting for a layout return. - scalability and infrastructure improvements Sincere thanks to all contributors, reviewers, testers, and bug reporters who participated in the v7.1 NFSD development cycle. * tag 'nfsd-7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux: (83 commits) NFSD: Docs: clean up pnfs server timeout docs nfsd: fix comment typo in nfsxdr nfsd: fix comment typo in nfs3xdr NFSD: convert callback RPC program to per-net namespace NFSD: use per-operation statidx for callback procedures svcrdma: Use contiguous pages for RDMA Read sink buffers SUNRPC: Add svc_rqst_page_release() helper SUNRPC: xdr.h: fix all kernel-doc warnings svcrdma: Factor out WR chain linking into helper svcrdma: Add Write chunk WRs to the RPC's Send WR chain svcrdma: Clean up use of rdma->sc_pd->device svcrdma: Clean up use of rdma->sc_pd->device in Receive paths svcrdma: Add fair queuing for Send Queue access SUNRPC: Optimize rq_respages allocation in svc_alloc_arg SUNRPC: Track consumed rq_pages entries svcrdma: preserve rq_next_page in svc_rdma_save_io_pages SUNRPC: Handle NULL entries in svc_rqst_release_pages SUNRPC: Allocate a separate Reply page array SUNRPC: Tighten bounds checking in svc_rqst_replace_page NFSD: Sign filehandles ...
This commit is contained in:
@@ -40,3 +40,33 @@ how to translate the device into a serial number from SCSI EVPD 0x80::
|
||||
|
||||
echo "fencing client ${CLIENT} serial ${EVPD}" >> /var/log/pnfsd-fence.log
|
||||
EOF
|
||||
|
||||
If the nfsd server needs to fence a non-responding client and the
|
||||
fencing operation fails, the server logs a warning message in the
|
||||
system log with the following format:
|
||||
|
||||
FENCE failed client[IP_address] clid[#n] device[dev_name]
|
||||
|
||||
where:
|
||||
|
||||
- IP_address: refers to the IP address of the affected client.
|
||||
- #n: indicates the unique client identifier.
|
||||
- dev_name: specifies the name of the block device related
|
||||
to the fencing attempt.
|
||||
|
||||
The server will repeatedly retry the operation indefinitely. During
|
||||
this time, access to the affected file is restricted for all other
|
||||
clients. This is to prevent potential data corruption if multiple
|
||||
clients access the same file simultaneously.
|
||||
|
||||
To restore access to the affected file for other clients, the admin
|
||||
needs to take the following actions:
|
||||
|
||||
- shutdown or power off the client being fenced.
|
||||
- manually expire the client to release all its state on the server::
|
||||
|
||||
echo 'expire' > /proc/fs/nfsd/clients/clid/ctl
|
||||
|
||||
where:
|
||||
|
||||
- clid: is the unique client identifier displayed in the system log.
|
||||
|
||||
@@ -22,3 +22,34 @@ option and the underlying SCSI device support persistent reservations.
|
||||
On the client make sure the kernel has the CONFIG_PNFS_BLOCK option
|
||||
enabled, and the file system is mounted using the NFSv4.1 protocol
|
||||
version (mount -o vers=4.1).
|
||||
|
||||
If the nfsd server needs to fence a non-responding client and the
|
||||
fencing operation fails, the server logs a warning message in the
|
||||
system log with the following format:
|
||||
|
||||
FENCE failed client[IP_address] clid[#n] device[dev_name]
|
||||
|
||||
where:
|
||||
|
||||
- IP_address: refers to the IP address of the affected client.
|
||||
- #n: indicates the unique client identifier.
|
||||
- dev_name: specifies the name of the block device related
|
||||
to the fencing attempt.
|
||||
|
||||
The server will repeatedly retry the operation indefinitely. During
|
||||
this time, access to the affected file is restricted for all other
|
||||
clients. This is to prevent potential data corruption if multiple
|
||||
clients access the same file simultaneously.
|
||||
|
||||
To restore access to the affected file for other clients, the admin
|
||||
needs to take the following actions:
|
||||
|
||||
- shutdown or power off the client being fenced.
|
||||
- manually expire the client to release all its state on the server::
|
||||
|
||||
echo 'expire' > /proc/fs/nfsd/clients/clid/ctl
|
||||
|
||||
where:
|
||||
|
||||
- clid: is the unique client identifier displayed in the system log.
|
||||
|
||||
|
||||
@@ -398,6 +398,7 @@ prototypes::
|
||||
bool (*lm_breaker_owns_lease)(struct file_lock *);
|
||||
bool (*lm_lock_expirable)(struct file_lock *);
|
||||
void (*lm_expire_lock)(void);
|
||||
bool (*lm_breaker_timedout)(struct file_lease *);
|
||||
|
||||
locking rules:
|
||||
|
||||
@@ -412,6 +413,7 @@ lm_breaker_owns_lease: yes no no
|
||||
lm_lock_expirable yes no no
|
||||
lm_expire_lock no no yes
|
||||
lm_open_conflict yes no no
|
||||
lm_breaker_timedout yes no no
|
||||
====================== ============= ================= =========
|
||||
|
||||
buffer_head
|
||||
|
||||
@@ -206,3 +206,88 @@ following flags are defined:
|
||||
all of an inode's dirty data on last close. Exports that behave this
|
||||
way should set EXPORT_OP_FLUSH_ON_CLOSE so that NFSD knows to skip
|
||||
waiting for writeback when closing such files.
|
||||
|
||||
Signed Filehandles
|
||||
------------------
|
||||
|
||||
To protect against filehandle guessing attacks, the Linux NFS server can be
|
||||
configured to sign filehandles with a Message Authentication Code (MAC).
|
||||
|
||||
Standard NFS filehandles are often predictable. If an attacker can guess
|
||||
a valid filehandle for a file they do not have permission to access via
|
||||
directory traversal, they may be able to bypass path-based permissions
|
||||
(though they still remain subject to inode-level permissions).
|
||||
|
||||
Signed filehandles prevent this by appending a MAC to the filehandle
|
||||
before it is sent to the client. Upon receiving a filehandle back from a
|
||||
client, the server re-calculates the MAC using its internal key and
|
||||
verifies it against the one provided. If the signatures do not match,
|
||||
the server treats the filehandle as invalid (returning NFS[34]ERR_STALE).
|
||||
|
||||
Note that signing filehandles provides integrity and authenticity but
|
||||
not confidentiality. The contents of the filehandle remain visible to
|
||||
the client; they simply cannot be forged or modified.
|
||||
|
||||
Configuration
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
To enable signed filehandles, the administrator must provide a signing
|
||||
key to the kernel and enable the "sign_fh" export option.
|
||||
|
||||
1. Providing a Key
|
||||
The signing key is managed via the nfsd netlink interface. This key
|
||||
is per-network-namespace and must be set before any exports using
|
||||
"sign_fh" become active.
|
||||
|
||||
2. Export Options
|
||||
The feature is controlled on a per-export basis in /etc/exports:
|
||||
|
||||
sign_fh
|
||||
Enables signing for all filehandles generated under this export.
|
||||
|
||||
no_sign_fh
|
||||
(Default) Disables signing.
|
||||
|
||||
Key Management and Rotation
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The security of this mechanism relies entirely on the secrecy of the
|
||||
signing key.
|
||||
|
||||
Initial Setup:
|
||||
The key should be generated using a high-quality random source and
|
||||
loaded early in the boot process or during the nfs-server startup
|
||||
sequence.
|
||||
|
||||
Changing Keys:
|
||||
If a key is changed while clients have active mounts, existing
|
||||
filehandles held by those clients will become invalid, resulting in
|
||||
"Stale file handle" errors on the client side.
|
||||
|
||||
Safe Rotation:
|
||||
Currently, there is no mechanism for "graceful" key rotation
|
||||
(maintaining multiple valid keys). Changing the key is an atomic
|
||||
operation that immediately invalidates all previous signatures.
|
||||
|
||||
Transitioning Exports
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
When adding or removing the "sign_fh" flag from an active export, the
|
||||
following behaviors should be expected:
|
||||
|
||||
+-------------------+---------------------------------------------------+
|
||||
| Change | Result for Existing Clients |
|
||||
+===================+===================================================+
|
||||
| Adding sign_fh | Clients holding unsigned filehandles will find |
|
||||
| | them rejected, as the server now expects a |
|
||||
| | signature. |
|
||||
+-------------------+---------------------------------------------------+
|
||||
| Removing sign_fh | Clients holding signed filehandles will find them |
|
||||
| | rejected, as the server now expects the |
|
||||
| | filehandle to end at its traditional boundary |
|
||||
| | without a MAC. |
|
||||
+-------------------+---------------------------------------------------+
|
||||
|
||||
Because filehandles are often cached persistently by clients, adding or
|
||||
removing this option should generally be done during a scheduled maintenance
|
||||
window involving a NFS client unmount/remount.
|
||||
|
||||
@@ -81,6 +81,11 @@ attribute-sets:
|
||||
-
|
||||
name: min-threads
|
||||
type: u32
|
||||
-
|
||||
name: fh-key
|
||||
type: binary
|
||||
checks:
|
||||
exact-len: 16
|
||||
-
|
||||
name: version
|
||||
attributes:
|
||||
@@ -163,6 +168,7 @@ operations:
|
||||
- leasetime
|
||||
- scope
|
||||
- min-threads
|
||||
- fh-key
|
||||
-
|
||||
name: threads-get
|
||||
doc: get the maximum number of running threads
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* This file was extracted by hand from
|
||||
* https://www.rfc-editor.org/rfc/rfc1813.html .
|
||||
*
|
||||
* Note that RFC 1813 is Informational. Its official date of
|
||||
* publication (June 1995) is before the IETF required its RFCs to
|
||||
* carry an explicit copyright or other IP ownership notices.
|
||||
*
|
||||
* Note also that RFC 1813 does not specify the whole NLM4 protocol.
|
||||
* In particular, the argument and result types are not present in
|
||||
* that document, and had to be reverse-engineered.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The NLMv4 protocol
|
||||
*/
|
||||
|
||||
pragma header nlm4;
|
||||
|
||||
/*
|
||||
* The following definitions are missing in RFC 1813,
|
||||
* but can be found in the OpenNetworking Network Lock
|
||||
* Manager protocol:
|
||||
*
|
||||
* https://pubs.opengroup.org/onlinepubs/9629799/chap10.htm
|
||||
*/
|
||||
|
||||
const LM_MAXSTRLEN = 1024;
|
||||
|
||||
const LM_MAXNAMELEN = 1025;
|
||||
|
||||
const MAXNETOBJ_SZ = 1024;
|
||||
|
||||
typedef opaque netobj<MAXNETOBJ_SZ>;
|
||||
|
||||
enum fsh4_mode {
|
||||
fsm_DN = 0, /* deny none */
|
||||
fsm_DR = 1, /* deny read */
|
||||
fsm_DW = 2, /* deny write */
|
||||
fsm_DRW = 3 /* deny read/write */
|
||||
};
|
||||
|
||||
enum fsh4_access {
|
||||
fsa_NONE = 0, /* for completeness */
|
||||
fsa_R = 1, /* read-only */
|
||||
fsa_W = 2, /* write-only */
|
||||
fsa_RW = 3 /* read/write */
|
||||
};
|
||||
|
||||
/*
|
||||
* The following definitions come from the OpenNetworking
|
||||
* Network Status Monitor protocol:
|
||||
*
|
||||
* https://pubs.opengroup.org/onlinepubs/9629799/chap11.htm
|
||||
*/
|
||||
|
||||
const SM_MAXSTRLEN = 1024;
|
||||
|
||||
/*
|
||||
* The NLM protocol as extracted from:
|
||||
* https://tools.ietf.org/html/rfc1813 Appendix II
|
||||
*/
|
||||
|
||||
typedef unsigned hyper uint64;
|
||||
|
||||
typedef hyper int64;
|
||||
|
||||
typedef unsigned long uint32;
|
||||
|
||||
typedef long int32;
|
||||
|
||||
enum nlm4_stats {
|
||||
NLM4_GRANTED = 0,
|
||||
NLM4_DENIED = 1,
|
||||
NLM4_DENIED_NOLOCKS = 2,
|
||||
NLM4_BLOCKED = 3,
|
||||
NLM4_DENIED_GRACE_PERIOD = 4,
|
||||
NLM4_DEADLCK = 5,
|
||||
NLM4_ROFS = 6,
|
||||
NLM4_STALE_FH = 7,
|
||||
NLM4_FBIG = 8,
|
||||
NLM4_FAILED = 9
|
||||
};
|
||||
|
||||
pragma big_endian nlm4_stats;
|
||||
|
||||
struct nlm4_holder {
|
||||
bool exclusive;
|
||||
int32 svid;
|
||||
netobj oh;
|
||||
uint64 l_offset;
|
||||
uint64 l_len;
|
||||
};
|
||||
|
||||
union nlm4_testrply switch (nlm4_stats stat) {
|
||||
case NLM4_DENIED:
|
||||
nlm4_holder holder;
|
||||
default:
|
||||
void;
|
||||
};
|
||||
|
||||
struct nlm4_stat {
|
||||
nlm4_stats stat;
|
||||
};
|
||||
|
||||
struct nlm4_res {
|
||||
netobj cookie;
|
||||
nlm4_stat stat;
|
||||
};
|
||||
|
||||
struct nlm4_testres {
|
||||
netobj cookie;
|
||||
nlm4_testrply stat;
|
||||
};
|
||||
|
||||
struct nlm4_lock {
|
||||
string caller_name<LM_MAXSTRLEN>;
|
||||
netobj fh;
|
||||
netobj oh;
|
||||
int32 svid;
|
||||
uint64 l_offset;
|
||||
uint64 l_len;
|
||||
};
|
||||
|
||||
struct nlm4_lockargs {
|
||||
netobj cookie;
|
||||
bool block;
|
||||
bool exclusive;
|
||||
nlm4_lock alock;
|
||||
bool reclaim;
|
||||
int32 state;
|
||||
};
|
||||
|
||||
struct nlm4_cancargs {
|
||||
netobj cookie;
|
||||
bool block;
|
||||
bool exclusive;
|
||||
nlm4_lock alock;
|
||||
};
|
||||
|
||||
struct nlm4_testargs {
|
||||
netobj cookie;
|
||||
bool exclusive;
|
||||
nlm4_lock alock;
|
||||
};
|
||||
|
||||
struct nlm4_unlockargs {
|
||||
netobj cookie;
|
||||
nlm4_lock alock;
|
||||
};
|
||||
|
||||
struct nlm4_share {
|
||||
string caller_name<LM_MAXSTRLEN>;
|
||||
netobj fh;
|
||||
netobj oh;
|
||||
fsh4_mode mode;
|
||||
fsh4_access access;
|
||||
};
|
||||
|
||||
struct nlm4_shareargs {
|
||||
netobj cookie;
|
||||
nlm4_share share;
|
||||
bool reclaim;
|
||||
};
|
||||
|
||||
struct nlm4_shareres {
|
||||
netobj cookie;
|
||||
nlm4_stats stat;
|
||||
int32 sequence;
|
||||
};
|
||||
|
||||
struct nlm4_notify {
|
||||
string name<LM_MAXNAMELEN>;
|
||||
int32 state;
|
||||
};
|
||||
|
||||
/*
|
||||
* Argument for the Linux-private SM_NOTIFY procedure
|
||||
*/
|
||||
const SM_PRIV_SIZE = 16;
|
||||
|
||||
struct nlm4_notifyargs {
|
||||
nlm4_notify notify;
|
||||
opaque private[SM_PRIV_SIZE];
|
||||
};
|
||||
|
||||
program NLM4_PROG {
|
||||
version NLM4_VERS {
|
||||
void NLMPROC4_NULL(void) = 0;
|
||||
nlm4_testres NLMPROC4_TEST(nlm4_testargs) = 1;
|
||||
nlm4_res NLMPROC4_LOCK(nlm4_lockargs) = 2;
|
||||
nlm4_res NLMPROC4_CANCEL(nlm4_cancargs) = 3;
|
||||
nlm4_res NLMPROC4_UNLOCK(nlm4_unlockargs) = 4;
|
||||
nlm4_res NLMPROC4_GRANTED(nlm4_testargs) = 5;
|
||||
void NLMPROC4_TEST_MSG(nlm4_testargs) = 6;
|
||||
void NLMPROC4_LOCK_MSG(nlm4_lockargs) = 7;
|
||||
void NLMPROC4_CANCEL_MSG(nlm4_cancargs) = 8;
|
||||
void NLMPROC4_UNLOCK_MSG(nlm4_unlockargs) = 9;
|
||||
void NLMPROC4_GRANTED_MSG(nlm4_testargs) = 10;
|
||||
void NLMPROC4_TEST_RES(nlm4_testres) = 11;
|
||||
void NLMPROC4_LOCK_RES(nlm4_res) = 12;
|
||||
void NLMPROC4_CANCEL_RES(nlm4_res) = 13;
|
||||
void NLMPROC4_UNLOCK_RES(nlm4_res) = 14;
|
||||
void NLMPROC4_GRANTED_RES(nlm4_res) = 15;
|
||||
void NLMPROC4_SM_NOTIFY(nlm4_notifyargs) = 16;
|
||||
nlm4_shareres NLMPROC4_SHARE(nlm4_shareargs) = 20;
|
||||
nlm4_shareres NLMPROC4_UNSHARE(nlm4_shareargs) = 21;
|
||||
nlm4_res NLMPROC4_NM_LOCK(nlm4_lockargs) = 22;
|
||||
void NLMPROC4_FREE_ALL(nlm4_notify) = 23;
|
||||
} = 4;
|
||||
} = 100021;
|
||||
+29
-1
@@ -9,5 +9,33 @@ obj-$(CONFIG_LOCKD) += lockd.o
|
||||
|
||||
lockd-y := clntlock.o clntproc.o clntxdr.o host.o svc.o svclock.o \
|
||||
svcshare.o svcproc.o svcsubs.o mon.o trace.o xdr.o netlink.o
|
||||
lockd-$(CONFIG_LOCKD_V4) += clnt4xdr.o xdr4.o svc4proc.o
|
||||
lockd-$(CONFIG_LOCKD_V4) += clnt4xdr.o svc4proc.o nlm4xdr_gen.o
|
||||
lockd-$(CONFIG_PROC_FS) += procfs.o
|
||||
|
||||
#
|
||||
# XDR code generation (requires Python and additional packages)
|
||||
#
|
||||
# The generated *xdr_gen.{h,c} files are checked into git. Normal kernel
|
||||
# builds do not require the xdrgen tool or its Python dependencies.
|
||||
#
|
||||
# Developers modifying .x files in Documentation/sunrpc/xdr/ should run
|
||||
# "make xdrgen" to regenerate the affected files.
|
||||
#
|
||||
.PHONY: xdrgen
|
||||
|
||||
XDRGEN = ../../tools/net/sunrpc/xdrgen/xdrgen
|
||||
|
||||
XDRGEN_DEFINITIONS = ../../include/linux/sunrpc/xdrgen/nlm4.h
|
||||
XDRGEN_DECLARATIONS = nlm4xdr_gen.h
|
||||
XDRGEN_SOURCE = nlm4xdr_gen.c
|
||||
|
||||
xdrgen: $(XDRGEN_DEFINITIONS) $(XDRGEN_DECLARATIONS) $(XDRGEN_SOURCE)
|
||||
|
||||
../../include/linux/sunrpc/xdrgen/nlm4.h: ../../Documentation/sunrpc/xdr/nlm4.x
|
||||
$(XDRGEN) definitions $< > $@
|
||||
|
||||
nlm4xdr_gen.h: ../../Documentation/sunrpc/xdr/nlm4.x
|
||||
$(XDRGEN) declarations $< > $@
|
||||
|
||||
nlm4xdr_gen.c: ../../Documentation/sunrpc/xdr/nlm4.x
|
||||
$(XDRGEN) source --peer server $< > $@
|
||||
|
||||
+3
-2
@@ -13,7 +13,8 @@
|
||||
#include <linux/sunrpc/xdr.h>
|
||||
#include <linux/sunrpc/clnt.h>
|
||||
#include <linux/sunrpc/stats.h>
|
||||
#include <linux/lockd/lockd.h>
|
||||
|
||||
#include "lockd.h"
|
||||
|
||||
#include <uapi/linux/nfs3.h>
|
||||
|
||||
@@ -284,7 +285,7 @@ static int decode_nlm4_holder(struct xdr_stream *xdr, struct nlm_res *result)
|
||||
fl->c.flc_type = exclusive != 0 ? F_WRLCK : F_RDLCK;
|
||||
p = xdr_decode_hyper(p, &l_offset);
|
||||
xdr_decode_hyper(p, &l_len);
|
||||
nlm4svc_set_file_lock_range(fl, l_offset, l_len);
|
||||
lockd_set_file_lock_range4(fl, l_offset, l_len);
|
||||
error = 0;
|
||||
out:
|
||||
return error;
|
||||
|
||||
+1
-1
@@ -15,9 +15,9 @@
|
||||
#include <linux/sunrpc/addr.h>
|
||||
#include <linux/sunrpc/svc.h>
|
||||
#include <linux/sunrpc/svc_xprt.h>
|
||||
#include <linux/lockd/lockd.h>
|
||||
#include <linux/kthread.h>
|
||||
|
||||
#include "lockd.h"
|
||||
#include "trace.h"
|
||||
|
||||
#define NLMDBG_FACILITY NLMDBG_CLIENT
|
||||
|
||||
+1
-1
@@ -18,8 +18,8 @@
|
||||
#include <linux/freezer.h>
|
||||
#include <linux/sunrpc/clnt.h>
|
||||
#include <linux/sunrpc/svc.h>
|
||||
#include <linux/lockd/lockd.h>
|
||||
|
||||
#include "lockd.h"
|
||||
#include "trace.h"
|
||||
|
||||
#define NLMDBG_FACILITY NLMDBG_CLIENT
|
||||
|
||||
+2
-1
@@ -15,7 +15,8 @@
|
||||
#include <linux/sunrpc/xdr.h>
|
||||
#include <linux/sunrpc/clnt.h>
|
||||
#include <linux/sunrpc/stats.h>
|
||||
#include <linux/lockd/lockd.h>
|
||||
|
||||
#include "lockd.h"
|
||||
|
||||
#include <uapi/linux/nfs2.h>
|
||||
|
||||
|
||||
+30
-1
@@ -16,13 +16,13 @@
|
||||
#include <linux/sunrpc/clnt.h>
|
||||
#include <linux/sunrpc/addr.h>
|
||||
#include <linux/sunrpc/svc.h>
|
||||
#include <linux/lockd/lockd.h>
|
||||
#include <linux/mutex.h>
|
||||
|
||||
#include <linux/sunrpc/svc_xprt.h>
|
||||
|
||||
#include <net/ipv6.h>
|
||||
|
||||
#include "lockd.h"
|
||||
#include "netns.h"
|
||||
|
||||
#define NLMDBG_FACILITY NLMDBG_HOSTCACHE
|
||||
@@ -306,6 +306,35 @@ void nlmclnt_release_host(struct nlm_host *host)
|
||||
}
|
||||
}
|
||||
|
||||
/* Callback for rpc_cancel_tasks() - matches all tasks for cancellation */
|
||||
static bool nlmclnt_match_all(const struct rpc_task *task, const void *data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* nlmclnt_shutdown_rpc_clnt - safely shut down NLM client RPC operations
|
||||
* @host: nlm_host to shut down
|
||||
*
|
||||
* Cancels outstanding RPC tasks and marks the client as shut down.
|
||||
* Synchronizes with nlmclnt_release_host() via nlm_host_mutex to prevent
|
||||
* races between shutdown and host destruction. Safe to call if h_rpcclnt
|
||||
* is NULL or already shut down.
|
||||
*/
|
||||
void nlmclnt_shutdown_rpc_clnt(struct nlm_host *host)
|
||||
{
|
||||
struct rpc_clnt *clnt;
|
||||
|
||||
mutex_lock(&nlm_host_mutex);
|
||||
clnt = host->h_rpcclnt;
|
||||
if (clnt) {
|
||||
clnt->cl_shutdown = 1;
|
||||
rpc_cancel_tasks(clnt, -EIO, nlmclnt_match_all, NULL);
|
||||
}
|
||||
mutex_unlock(&nlm_host_mutex);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(nlmclnt_shutdown_rpc_clnt);
|
||||
|
||||
/**
|
||||
* nlmsvc_lookup_host - Find an NLM host handle matching a remote client
|
||||
* @rqstp: incoming NLM request
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* linux/include/linux/lockd/lockd.h
|
||||
*
|
||||
* General-purpose lockd include file.
|
||||
*
|
||||
* Copyright (C) 1996 Olaf Kirch <okir@monad.swb.de>
|
||||
*/
|
||||
|
||||
#ifndef LINUX_LOCKD_LOCKD_H
|
||||
#define LINUX_LOCKD_LOCKD_H
|
||||
|
||||
/* XXX: a lot of this should really be under fs/lockd. */
|
||||
#ifndef _LOCKD_LOCKD_H
|
||||
#define _LOCKD_LOCKD_H
|
||||
|
||||
#include <linux/exportfs.h>
|
||||
#include <linux/in.h>
|
||||
@@ -20,14 +14,34 @@
|
||||
#include <linux/kref.h>
|
||||
#include <linux/refcount.h>
|
||||
#include <linux/utsname.h>
|
||||
#include "nlm.h"
|
||||
#include <linux/lockd/bind.h>
|
||||
#include <linux/lockd/xdr.h>
|
||||
#ifdef CONFIG_LOCKD_V4
|
||||
#include <linux/lockd/xdr4.h>
|
||||
#endif
|
||||
#include <linux/lockd/debug.h>
|
||||
#include "xdr.h"
|
||||
#include <linux/sunrpc/debug.h>
|
||||
#include <linux/sunrpc/svc.h>
|
||||
|
||||
/*
|
||||
* Enable lockd debugging.
|
||||
* Requires CONFIG_SUNRPC_DEBUG.
|
||||
*/
|
||||
#undef ifdebug
|
||||
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
|
||||
# define ifdebug(flag) if (unlikely(nlm_debug & NLMDBG_##flag))
|
||||
#else
|
||||
# define ifdebug(flag) if (0)
|
||||
#endif
|
||||
|
||||
#define NLMDBG_SVC 0x0001
|
||||
#define NLMDBG_CLIENT 0x0002
|
||||
#define NLMDBG_CLNTLOCK 0x0004
|
||||
#define NLMDBG_SVCLOCK 0x0008
|
||||
#define NLMDBG_MONITOR 0x0010
|
||||
#define NLMDBG_CLNTSUBS 0x0020
|
||||
#define NLMDBG_SVCSUBS 0x0040
|
||||
#define NLMDBG_HOSTCACHE 0x0080
|
||||
#define NLMDBG_XDR 0x0100
|
||||
#define NLMDBG_ALL 0x7fff
|
||||
|
||||
/*
|
||||
* Version string
|
||||
*/
|
||||
@@ -38,6 +52,22 @@
|
||||
*/
|
||||
#define LOCKD_DFLT_TIMEO 10
|
||||
|
||||
/* error codes new to NLMv4 */
|
||||
#define nlm4_deadlock cpu_to_be32(NLM_DEADLCK)
|
||||
#define nlm4_rofs cpu_to_be32(NLM_ROFS)
|
||||
#define nlm4_stale_fh cpu_to_be32(NLM_STALE_FH)
|
||||
#define nlm4_fbig cpu_to_be32(NLM_FBIG)
|
||||
#define nlm4_failed cpu_to_be32(NLM_FAILED)
|
||||
|
||||
/*
|
||||
* Internal-use status codes, not to be placed on the wire.
|
||||
* Version handlers translate these to appropriate wire values.
|
||||
*/
|
||||
#define nlm__int__drop_reply cpu_to_be32(30000)
|
||||
#define nlm__int__deadlock cpu_to_be32(30001)
|
||||
#define nlm__int__stale_fh cpu_to_be32(30002)
|
||||
#define nlm__int__failed cpu_to_be32(30003)
|
||||
|
||||
/*
|
||||
* Lockd host handle (used both by the client and server personality).
|
||||
*/
|
||||
@@ -149,6 +179,8 @@ struct nlm_rqst {
|
||||
void * a_callback_data; /* sent to nlmclnt_operations callbacks */
|
||||
};
|
||||
|
||||
struct nlm_share;
|
||||
|
||||
/*
|
||||
* This struct describes a file held open by lockd on behalf of
|
||||
* an NFS client.
|
||||
@@ -196,9 +228,10 @@ struct nlm_block {
|
||||
* Global variables
|
||||
*/
|
||||
extern const struct rpc_program nlm_program;
|
||||
extern const struct svc_procedure nlmsvc_procedures[24];
|
||||
extern const struct svc_version nlmsvc_version1;
|
||||
extern const struct svc_version nlmsvc_version3;
|
||||
#ifdef CONFIG_LOCKD_V4
|
||||
extern const struct svc_procedure nlmsvc_procedures4[24];
|
||||
extern const struct svc_version nlmsvc_version4;
|
||||
#endif
|
||||
extern int nlmsvc_grace_period;
|
||||
extern unsigned long nlm_timeout;
|
||||
@@ -226,6 +259,10 @@ int nlmclnt_reclaim(struct nlm_host *, struct file_lock *,
|
||||
struct nlm_rqst *);
|
||||
void nlmclnt_next_cookie(struct nlm_cookie *);
|
||||
|
||||
#ifdef CONFIG_LOCKD_V4
|
||||
extern const struct rpc_version nlm_version4;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Host cache
|
||||
*/
|
||||
@@ -289,6 +326,7 @@ void nlmsvc_traverse_blocks(struct nlm_host *, struct nlm_file *,
|
||||
void nlmsvc_grant_reply(struct nlm_cookie *, __be32);
|
||||
void nlmsvc_release_call(struct nlm_rqst *);
|
||||
void nlmsvc_locks_init_private(struct file_lock *, struct nlm_host *, pid_t);
|
||||
int nlmsvc_dispatch(struct svc_rqst *rqstp);
|
||||
|
||||
/*
|
||||
* File handling for the server personality
|
||||
@@ -302,12 +340,6 @@ void nlmsvc_mark_resources(struct net *);
|
||||
void nlmsvc_free_host_resources(struct nlm_host *);
|
||||
void nlmsvc_invalidate_all(void);
|
||||
|
||||
/*
|
||||
* Cluster failover support
|
||||
*/
|
||||
int nlmsvc_unlock_all_by_sb(struct super_block *sb);
|
||||
int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr);
|
||||
|
||||
static inline struct file *nlmsvc_file_file(const struct nlm_file *file)
|
||||
{
|
||||
return file->f_file[O_RDONLY] ?
|
||||
@@ -390,6 +422,31 @@ static inline int nlm_compare_locks(const struct file_lock *fl1,
|
||||
&&(fl1->c.flc_type == fl2->c.flc_type || fl2->c.flc_type == F_UNLCK);
|
||||
}
|
||||
|
||||
/**
|
||||
* lockd_set_file_lock_range4 - set the byte range of a file_lock
|
||||
* @fl: file_lock whose length fields are to be initialized
|
||||
* @off: starting offset of the lock, in bytes
|
||||
* @len: length of the byte range, in bytes, or zero
|
||||
*
|
||||
* The NLMv4 protocol represents lock byte ranges as (start, length),
|
||||
* where length zero means "lock to end of file." The kernel's file_lock
|
||||
* structure uses (start, end) representation. Convert from NLMv4 format
|
||||
* to file_lock format, clamping the starting offset and treating
|
||||
* arithmetic overflow as "lock to EOF."
|
||||
*/
|
||||
static inline void
|
||||
lockd_set_file_lock_range4(struct file_lock *fl, u64 off, u64 len)
|
||||
{
|
||||
u64 clamped_off = (off > OFFSET_MAX) ? OFFSET_MAX : off;
|
||||
s64 end = clamped_off + len - 1;
|
||||
|
||||
fl->fl_start = clamped_off;
|
||||
if (len == 0 || end < 0)
|
||||
fl->fl_end = OFFSET_MAX;
|
||||
else
|
||||
fl->fl_end = end;
|
||||
}
|
||||
|
||||
extern const struct lock_manager_operations nlmsvc_lock_operations;
|
||||
|
||||
#endif /* LINUX_LOCKD_LOCKD_H */
|
||||
#endif /* _LOCKD_LOCKD_H */
|
||||
+1
-1
@@ -16,10 +16,10 @@
|
||||
#include <linux/sunrpc/addr.h>
|
||||
#include <linux/sunrpc/xprtsock.h>
|
||||
#include <linux/sunrpc/svc.h>
|
||||
#include <linux/lockd/lockd.h>
|
||||
|
||||
#include <linux/unaligned.h>
|
||||
|
||||
#include "lockd.h"
|
||||
#include "netns.h"
|
||||
|
||||
#define NLMDBG_FACILITY NLMDBG_MONITOR
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* linux/include/linux/lockd/nlm.h
|
||||
*
|
||||
* Declarations for the Network Lock Manager protocol.
|
||||
*
|
||||
* Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
|
||||
*/
|
||||
|
||||
#ifndef LINUX_LOCKD_NLM_H
|
||||
#define LINUX_LOCKD_NLM_H
|
||||
#ifndef _LOCKD_NLM_H
|
||||
#define _LOCKD_NLM_H
|
||||
|
||||
|
||||
/* Maximum file offset in file_lock.fl_end */
|
||||
@@ -55,4 +53,4 @@ enum {
|
||||
#define NLMPROC_NM_LOCK 22
|
||||
#define NLMPROC_FREE_ALL 23
|
||||
|
||||
#endif /* LINUX_LOCKD_NLM_H */
|
||||
#endif /* _LOCKD_NLM_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/* Generated by xdrgen. Manual edits will be lost. */
|
||||
/* XDR specification file: ../../Documentation/sunrpc/xdr/nlm4.x */
|
||||
/* XDR specification modification time: Thu Dec 25 13:10:19 2025 */
|
||||
|
||||
#ifndef _LINUX_XDRGEN_NLM4_DECL_H
|
||||
#define _LINUX_XDRGEN_NLM4_DECL_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
#include <linux/sunrpc/xdr.h>
|
||||
#include <linux/sunrpc/xdrgen/_defs.h>
|
||||
#include <linux/sunrpc/xdrgen/_builtins.h>
|
||||
#include <linux/sunrpc/xdrgen/nlm4.h>
|
||||
|
||||
bool nlm4_svc_decode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr);
|
||||
bool nlm4_svc_decode_nlm4_testargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
|
||||
bool nlm4_svc_decode_nlm4_lockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
|
||||
bool nlm4_svc_decode_nlm4_cancargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
|
||||
bool nlm4_svc_decode_nlm4_unlockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
|
||||
bool nlm4_svc_decode_nlm4_testres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
|
||||
bool nlm4_svc_decode_nlm4_res(struct svc_rqst *rqstp, struct xdr_stream *xdr);
|
||||
bool nlm4_svc_decode_nlm4_notifyargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
|
||||
bool nlm4_svc_decode_nlm4_shareargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
|
||||
bool nlm4_svc_decode_nlm4_notify(struct svc_rqst *rqstp, struct xdr_stream *xdr);
|
||||
|
||||
bool nlm4_svc_encode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr);
|
||||
bool nlm4_svc_encode_nlm4_testres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
|
||||
bool nlm4_svc_encode_nlm4_res(struct svc_rqst *rqstp, struct xdr_stream *xdr);
|
||||
bool nlm4_svc_encode_nlm4_shareres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
|
||||
|
||||
#endif /* _LINUX_XDRGEN_NLM4_DECL_H */
|
||||
@@ -1,14 +1,15 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* linux/include/linux/lockd/share.h
|
||||
*
|
||||
* DOS share management for lockd.
|
||||
*
|
||||
* Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
|
||||
*/
|
||||
|
||||
#ifndef LINUX_LOCKD_SHARE_H
|
||||
#define LINUX_LOCKD_SHARE_H
|
||||
#ifndef _LOCKD_SHARE_H
|
||||
#define _LOCKD_SHARE_H
|
||||
|
||||
/* Synthetic svid for lockowner lookup during share operations */
|
||||
#define LOCKD_SHARE_SVID (~(u32)0)
|
||||
|
||||
/*
|
||||
* DOS share for a specific file
|
||||
@@ -22,11 +23,11 @@ struct nlm_share {
|
||||
u32 s_mode; /* deny mode */
|
||||
};
|
||||
|
||||
__be32 nlmsvc_share_file(struct nlm_host *, struct nlm_file *,
|
||||
struct nlm_args *);
|
||||
__be32 nlmsvc_unshare_file(struct nlm_host *, struct nlm_file *,
|
||||
struct nlm_args *);
|
||||
__be32 nlmsvc_share_file(struct nlm_host *host, struct nlm_file *file,
|
||||
struct xdr_netobj *oh, u32 access, u32 mode);
|
||||
__be32 nlmsvc_unshare_file(struct nlm_host *host, struct nlm_file *file,
|
||||
struct xdr_netobj *oh);
|
||||
void nlmsvc_traverse_shares(struct nlm_host *, struct nlm_file *,
|
||||
nlm_host_match_fn_t);
|
||||
|
||||
#endif /* LINUX_LOCKD_SHARE_H */
|
||||
#endif /* _LOCKD_SHARE_H */
|
||||
+12
-38
@@ -36,15 +36,14 @@
|
||||
#include <net/ip.h>
|
||||
#include <net/addrconf.h>
|
||||
#include <net/ipv6.h>
|
||||
#include <linux/lockd/lockd.h>
|
||||
#include <linux/nfs.h>
|
||||
|
||||
#include "lockd.h"
|
||||
#include "netns.h"
|
||||
#include "procfs.h"
|
||||
#include "netlink.h"
|
||||
|
||||
#define NLMDBG_FACILITY NLMDBG_SVC
|
||||
#define LOCKD_BUFSIZE (1024 + NLMSVC_XDRSIZE)
|
||||
|
||||
static struct svc_program nlmsvc_program;
|
||||
|
||||
@@ -319,6 +318,7 @@ static struct notifier_block lockd_inet6addr_notifier = {
|
||||
static int lockd_get(void)
|
||||
{
|
||||
struct svc_serv *serv;
|
||||
unsigned int bufsize;
|
||||
int error;
|
||||
|
||||
if (nlmsvc_serv) {
|
||||
@@ -334,7 +334,15 @@ static int lockd_get(void)
|
||||
printk(KERN_WARNING
|
||||
"lockd_up: no pid, %d users??\n", nlmsvc_users);
|
||||
|
||||
serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, lockd);
|
||||
#ifdef CONFIG_LOCKD_V4
|
||||
bufsize = 1024 + max3(nlmsvc_version1.vs_xdrsize,
|
||||
nlmsvc_version3.vs_xdrsize,
|
||||
nlmsvc_version4.vs_xdrsize);
|
||||
#else
|
||||
bufsize = 1024 + max(nlmsvc_version1.vs_xdrsize,
|
||||
nlmsvc_version3.vs_xdrsize);
|
||||
#endif
|
||||
serv = svc_create(&nlmsvc_program, bufsize, lockd);
|
||||
if (!serv) {
|
||||
printk(KERN_WARNING "lockd_up: create service failed\n");
|
||||
return -ENOMEM;
|
||||
@@ -640,7 +648,7 @@ module_exit(exit_nlm);
|
||||
* %0: Processing complete; do not send a Reply
|
||||
* %1: Processing complete; send Reply in rqstp->rq_res
|
||||
*/
|
||||
static int nlmsvc_dispatch(struct svc_rqst *rqstp)
|
||||
int nlmsvc_dispatch(struct svc_rqst *rqstp)
|
||||
{
|
||||
const struct svc_procedure *procp = rqstp->rq_procinfo;
|
||||
__be32 *statp = rqstp->rq_accept_statp;
|
||||
@@ -671,40 +679,6 @@ out_encode_err:
|
||||
/*
|
||||
* Define NLM program and procedures
|
||||
*/
|
||||
static DEFINE_PER_CPU_ALIGNED(unsigned long, nlmsvc_version1_count[17]);
|
||||
static const struct svc_version nlmsvc_version1 = {
|
||||
.vs_vers = 1,
|
||||
.vs_nproc = 17,
|
||||
.vs_proc = nlmsvc_procedures,
|
||||
.vs_count = nlmsvc_version1_count,
|
||||
.vs_dispatch = nlmsvc_dispatch,
|
||||
.vs_xdrsize = NLMSVC_XDRSIZE,
|
||||
};
|
||||
|
||||
static DEFINE_PER_CPU_ALIGNED(unsigned long,
|
||||
nlmsvc_version3_count[ARRAY_SIZE(nlmsvc_procedures)]);
|
||||
static const struct svc_version nlmsvc_version3 = {
|
||||
.vs_vers = 3,
|
||||
.vs_nproc = ARRAY_SIZE(nlmsvc_procedures),
|
||||
.vs_proc = nlmsvc_procedures,
|
||||
.vs_count = nlmsvc_version3_count,
|
||||
.vs_dispatch = nlmsvc_dispatch,
|
||||
.vs_xdrsize = NLMSVC_XDRSIZE,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_LOCKD_V4
|
||||
static DEFINE_PER_CPU_ALIGNED(unsigned long,
|
||||
nlmsvc_version4_count[ARRAY_SIZE(nlmsvc_procedures4)]);
|
||||
static const struct svc_version nlmsvc_version4 = {
|
||||
.vs_vers = 4,
|
||||
.vs_nproc = ARRAY_SIZE(nlmsvc_procedures4),
|
||||
.vs_proc = nlmsvc_procedures4,
|
||||
.vs_count = nlmsvc_version4_count,
|
||||
.vs_dispatch = nlmsvc_dispatch,
|
||||
.vs_xdrsize = NLMSVC_XDRSIZE,
|
||||
};
|
||||
#endif
|
||||
|
||||
static const struct svc_version *nlmsvc_version[] = {
|
||||
[1] = &nlmsvc_version1,
|
||||
[3] = &nlmsvc_version3,
|
||||
|
||||
+1231
-555
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user