nfsdctl: inspect only the command request policy
Subsystems (2)
PATCH 1/1 nfsdctl: inspect only the command request policy
CTRL_CMD_GETPOLICY also describes nested attribute policies. Counting those attributes as command capabilities can enable unsupported flags. Select the do-operation policy index before computing its maximum, and keep that index across dump messages.
Signed-off-by Giuseppe Piscitelli <[email protected]>
Assisted-by OpenAI Codex
---
A four-case callback harness passed with this change (one case passed before). An isolated Linux 7.3 VM passed nfsdctl threads 0/autostart and NFSv3/v4.2 write/read, sync and root-squash checks with nfs-utils 3.1.1. These results are from October 23; no new build or runtime test was run.
utils/nfsdctl/nfsdctl.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
utils/nfsdctl/nfsdctl.c +20 -4
@@ -561,10 +561,15 @@ static int nfsd_nl_family_setup(struct nl_sock *sock)return nfsd_nl_family; } +struct nfsd_cmd_policy { +int *max_nlattr; +int policy_index; +}; +static int getpolicy_handler (struct nl_msg *msg,void *arg) {struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); -int *max_nlattr = arg; +struct nfsd_cmd_policy *policy = arg;struct nlattr *attr;int rem;
@@ -572,13 +577,23 @@ static int getpolicy_handler(struct nl_msg *msg, void *arg)struct nlattr *a, *b;int i, j; +if (nla_type (attr) ==CTRL_ATTR_OP_POLICY ) { +nla_for_each_nested (a, attr, i) { + b =nla_find (nla_data (a),nla_len (a), +CTRL_ATTR_POLICY_DO ); +if (b) + policy->policy_index =nla_get_u32 (b); + } + }if (nla_type (attr) ==CTRL_ATTR_POLICY ) {nla_for_each_nested (a, attr, i) { +if (nla_type (a) != policy->policy_index) +continue ;nla_for_each_nested (b, a, j) {int idx =nla_type (b); -if (*max_nlattr < idx) - *max_nlattr = idx; +if (*policy->max_nlattr < idx) + *policy->max_nlattr = idx; } } }
@@ -589,6 +604,7 @@ static int getpolicy_handler(struct nl_msg *msg, void *arg)static int query_nfsd_nl_cmd_policy (struct nl_sock *sock,int cmd,int *max_nlattr) { +struct nfsd_cmd_policy policy = { max_nlattr,-1 };struct genlmsghdr *ghdr;struct nlmsghdr *nlh;struct nl_msg *msg;
@@ -625,7 +641,7 @@ static int query_nfsd_nl_cmd_policy(struct nl_sock *sock, int cmd,nl_cb_err (cb,NL_CB_CUSTOM , error_handler, &ret);nl_cb_set (cb,NL_CB_FINISH ,NL_CB_CUSTOM , finish_handler, &ret);nl_cb_set (cb,NL_CB_ACK ,NL_CB_CUSTOM , ack_handler, &ret); -nl_cb_set (cb,NL_CB_VALID ,NL_CB_CUSTOM , getpolicy_handler, max_nlattr); +nl_cb_set (cb,NL_CB_VALID ,NL_CB_CUSTOM , getpolicy_handler, &policy);while (ret >0 )nl_recvmsgs (sock, cb);
Signature · 1 line
2.54.0