summaryrefslogtreecommitdiff
path: root/include/net/netlink.h
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2022-10-27 14:25:53 -0700
committerDavid S. Miller <davem@davemloft.net>2022-10-31 09:13:10 +0000
commit738136a0e3757a8534df3ad97d6ff6d7f429f6c1 (patch)
tree4ea24529d3600c1aa926aaa791f1085af6c111e6 /include/net/netlink.h
parenteca485d22165695587bed02d8b9d0f7f44246c4a (diff)
netlink: split up copies in the ack construction
Clean up the use of unsafe_memcpy() by adding a flexible array at the end of netlink message header and splitting up the header and data copies. Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/netlink.h')
-rw-r--r--include/net/netlink.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/include/net/netlink.h b/include/net/netlink.h
index 4418b1981e31..784b4688fc6f 100644
--- a/include/net/netlink.h
+++ b/include/net/netlink.h
@@ -932,6 +932,27 @@ static inline struct nlmsghdr *nlmsg_put(struct sk_buff *skb, u32 portid, u32 se
}
/**
+ * nlmsg_append - Add more data to a nlmsg in a skb
+ * @skb: socket buffer to store message in
+ * @size: length of message payload
+ *
+ * Append data to an existing nlmsg, used when constructing a message
+ * with multiple fixed-format headers (which is rare).
+ * Returns NULL if the tailroom of the skb is insufficient to store
+ * the extra payload.
+ */
+static inline void *nlmsg_append(struct sk_buff *skb, u32 size)
+{
+ if (unlikely(skb_tailroom(skb) < NLMSG_ALIGN(size)))
+ return NULL;
+
+ if (NLMSG_ALIGN(size) - size)
+ memset(skb_tail_pointer(skb) + size, 0,
+ NLMSG_ALIGN(size) - size);
+ return __skb_put(skb, NLMSG_ALIGN(size));
+}
+
+/**
* nlmsg_put_answer - Add a new callback based netlink message to an skb
* @skb: socket buffer to store message in
* @cb: netlink callback