Skip to content

Commit a9c4b1d

Browse files
chrboeaxboe
authored andcommitted
drbd: remove DRBD_GENLA_F_MANDATORY flag handling
DRBD used a custom mechanism to mark netlink attributes as "mandatory": bit 14 of nla_type was repurposed as DRBD_GENLA_F_MANDATORY. Attributes sent from userspace that had this bit present and that were unknown to the kernel would lead to an error. Since commit ef6243a ("genetlink: optionally validate strictly/dumps"), the generic netlink layer rejects unknown top-level attributes when strict validation is enabled. DRBD never opted out of strict validation, so unknown top-level attributes are already rejected by the netlink core. The mandatory flag mechanism was required for nested attributes, because these are parsed liberally, silently dropping attributes unknown to the kernel. This prepares for the move to a new YNL-based family, which will use the now-default strict parsing. The current family is not expected to gain any new attributes, which makes this change safe. Old userspace that still sets bit 14 is unaffected: nla_type() strips it before __nla_validate_parse() performs attribute validation, so the bit never reaches DRBD. Remove all references to the mandatory flag in DRBD. Cc: Johannes Berg <johannes.berg@intel.com> Cc: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com> Link: https://patch.msgid.link/20260403132953.2248751-1-christoph.boehmwalder@linbit.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e9b004f commit a9c4b1d

7 files changed

Lines changed: 114 additions & 197 deletions

File tree

drivers/block/drbd/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ drbd-y := drbd_buildtag.o drbd_bitmap.o drbd_proc.o
33
drbd-y += drbd_worker.o drbd_receiver.o drbd_req.o drbd_actlog.o
44
drbd-y += drbd_main.o drbd_strings.o drbd_nl.o
55
drbd-y += drbd_interval.o drbd_state.o
6-
drbd-y += drbd_nla.o
76
drbd-$(CONFIG_DEBUG_FS) += drbd_debugfs.o
87

98
obj-$(CONFIG_BLK_DEV_DRBD) += drbd.o

drivers/block/drbd/drbd_nl.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ int drbd_adm_dump_peer_devices_done(struct netlink_callback *cb);
7474
int drbd_adm_get_initial_state(struct sk_buff *skb, struct netlink_callback *cb);
7575

7676
#include <linux/drbd_genl_api.h>
77-
#include "drbd_nla.h"
7877

7978
static int drbd_pre_doit(const struct genl_split_ops *ops,
8079
struct sk_buff *skb, struct genl_info *info);
@@ -239,14 +238,14 @@ static int drbd_adm_prepare(struct drbd_config_context *adm_ctx,
239238
goto fail;
240239

241240
/* and assign stuff to the adm_ctx */
242-
nla = nested_attr_tb[__nla_type(T_ctx_volume)];
241+
nla = nested_attr_tb[T_ctx_volume];
243242
if (nla)
244243
adm_ctx->volume = nla_get_u32(nla);
245-
nla = nested_attr_tb[__nla_type(T_ctx_resource_name)];
244+
nla = nested_attr_tb[T_ctx_resource_name];
246245
if (nla)
247246
adm_ctx->resource_name = nla_data(nla);
248-
adm_ctx->my_addr = nested_attr_tb[__nla_type(T_ctx_my_addr)];
249-
adm_ctx->peer_addr = nested_attr_tb[__nla_type(T_ctx_peer_addr)];
247+
adm_ctx->my_addr = nested_attr_tb[T_ctx_my_addr];
248+
adm_ctx->peer_addr = nested_attr_tb[T_ctx_peer_addr];
250249
if ((adm_ctx->my_addr &&
251250
nla_len(adm_ctx->my_addr) > sizeof(adm_ctx->connection->my_addr)) ||
252251
(adm_ctx->peer_addr &&
@@ -825,7 +824,6 @@ drbd_set_role(struct drbd_device *const device, enum drbd_role new_role, int for
825824
static const char *from_attrs_err_to_txt(int err)
826825
{
827826
return err == -ENOMSG ? "required attribute missing" :
828-
err == -EOPNOTSUPP ? "unknown mandatory attribute" :
829827
err == -EEXIST ? "can not change invariant setting" :
830828
"invalid attribute value";
831829
}
@@ -3303,14 +3301,13 @@ static int nla_put_drbd_cfg_context(struct sk_buff *skb,
33033301
static struct nlattr *find_cfg_context_attr(const struct nlmsghdr *nlh, int attr)
33043302
{
33053303
const unsigned hdrlen = GENL_HDRLEN + GENL_MAGIC_FAMILY_HDRSZ;
3306-
const int maxtype = ARRAY_SIZE(drbd_cfg_context_nl_policy) - 1;
33073304
struct nlattr *nla;
33083305

33093306
nla = nla_find(nlmsg_attrdata(nlh, hdrlen), nlmsg_attrlen(nlh, hdrlen),
33103307
DRBD_NLA_CFG_CONTEXT);
33113308
if (!nla)
33123309
return NULL;
3313-
return drbd_nla_find_nested(maxtype, nla, __nla_type(attr));
3310+
return nla_find_nested(nla, attr);
33143311
}
33153312

33163313
static void resource_to_info(struct resource_info *, struct drbd_resource *);
@@ -4068,7 +4065,6 @@ int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb)
40684065
struct nlattr *nla;
40694066
const char *resource_name;
40704067
struct drbd_resource *resource;
4071-
int maxtype;
40724068

40734069
/* Is this a followup call? */
40744070
if (cb->args[0]) {
@@ -4088,10 +4084,7 @@ int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb)
40884084
/* No explicit context given. Dump all. */
40894085
if (!nla)
40904086
goto dump;
4091-
maxtype = ARRAY_SIZE(drbd_cfg_context_nl_policy) - 1;
4092-
nla = drbd_nla_find_nested(maxtype, nla, __nla_type(T_ctx_resource_name));
4093-
if (IS_ERR(nla))
4094-
return PTR_ERR(nla);
4087+
nla = nla_find_nested(nla, T_ctx_resource_name);
40954088
/* context given, but no name present? */
40964089
if (!nla)
40974090
return -EINVAL;

drivers/block/drbd/drbd_nla.c

Lines changed: 0 additions & 56 deletions
This file was deleted.

drivers/block/drbd/drbd_nla.h

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)