lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 23 Aug 2022 21:50:21 -0700
From:   Jakub Kicinski <kuba@...nel.org>
To:     davem@...emloft.net
Cc:     netdev@...r.kernel.org, edumazet@...gle.com, pabeni@...hat.com,
        mkubecek@...e.cz, johannes@...solutions.net,
        Jakub Kicinski <kuba@...nel.org>
Subject: [PATCH net-next 3/6] genetlink: add helper for checking required attrs and use it in devlink

Add a genetlink wrapper for checking if a required attribute
is present in the root nest. Because we want the offset to
point at the inner-most header we need to differentiate
between families which have userhdr and those which don't.
Only ovs, tipc and drbd access userhdr, and they all have
additional userhdr so it's safe to set userhdr to NULL
for families which depend purely on attributes.

Signed-off-by: Jakub Kicinski <kuba@...nel.org>
---
 include/net/genetlink.h | 14 ++++++++++++++
 net/netlink/genetlink.c |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/net/genetlink.h b/include/net/genetlink.h
index 56a50e1c51b9..5da038e1b39e 100644
--- a/include/net/genetlink.h
+++ b/include/net/genetlink.h
@@ -107,6 +107,20 @@ static inline void genl_info_net_set(struct genl_info *info, struct net *net)
 
 #define GENL_SET_ERR_MSG(info, msg) NL_SET_ERR_MSG((info)->extack, msg)
 
+/* Report that a root attribute is missing */
+#define GENL_REQ_ATTR_CHECK(info, attr) ({				\
+	struct genl_info *__info = (info);				\
+	u32 __attr = (attr);						\
+	int __retval;							\
+									\
+	__retval = !__info->attrs[__attr];				\
+	if (__retval)							\
+		NL_SET_ERR_ATTR_MISS(__info->extack,			\
+				     __info->userhdr ? : __info->genlhdr, \
+				     __attr);				\
+	__retval;							\
+})
+
 enum genl_validate_flags {
 	GENL_DONT_VALIDATE_STRICT		= BIT(0),
 	GENL_DONT_VALIDATE_DUMP			= BIT(1),
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 57010927e20a..37805115e637 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -716,7 +716,7 @@ static int genl_family_rcv_msg_doit(const struct genl_family *family,
 	info.snd_portid = NETLINK_CB(skb).portid;
 	info.nlhdr = nlh;
 	info.genlhdr = nlmsg_data(nlh);
-	info.userhdr = nlmsg_data(nlh) + GENL_HDRLEN;
+	info.userhdr = family->hdrsize ? nlmsg_data(nlh) + GENL_HDRLEN : NULL;
 	info.attrs = attrbuf;
 	info.extack = extack;
 	genl_info_net_set(&info, net);
-- 
2.37.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ