diff mbox series

[net] net: dcb: Validate netlink message in DCB handler

Message ID a2a9b88418f3a58ef211b718f2970128ef9e3793.1608673640.git.me@pmachata.org (mailing list archive)
State Accepted
Delegated to: Netdev Maintainers
Headers show
Series [net] net: dcb: Validate netlink message in DCB handler | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net
netdev/subject_prefix success Link
netdev/cc_maintainers warning 4 maintainers not CCed: gaurav1086@gmail.com nipa@patchwork.hopto.org jiri@nvidia.com andrew@lunn.ch
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Petr Machata Dec. 22, 2020, 9:49 p.m. UTC
DCB uses the same handler function for both RTM_GETDCB and RTM_SETDCB
messages. dcb_doit() bounces RTM_SETDCB mesasges if the user does not have
the CAP_NET_ADMIN capability.

However, the operation to be performed is not decided from the DCB message
type, but from the DCB command. Thus DCB_CMD_*_GET commands are used for
reading DCB objects, the corresponding SET and DEL commands are used for
manipulation.

The assumption is that set-like commands will be sent via an RTM_SETDCB
message, and get-like ones via RTM_GETDCB. However, this assumption is not
enforced.

It is therefore possible to manipulate DCB objects without CAP_NET_ADMIN
capability by sending the corresponding command in an RTM_GETDCB message.
That is a bug. Fix it by validating the type of the request message against
the type used for the response.

Fixes: 2f90b8657ec9 ("ixgbe: this patch adds support for DCB to the kernel and ixgbe driver")
Signed-off-by: Petr Machata <me@pmachata.org>
---
 net/dcb/dcbnl.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Jakub Kicinski Dec. 23, 2020, 8:22 p.m. UTC | #1
On Tue, 22 Dec 2020 22:49:44 +0100 Petr Machata wrote:
> DCB uses the same handler function for both RTM_GETDCB and RTM_SETDCB
> messages. dcb_doit() bounces RTM_SETDCB mesasges if the user does not have
> the CAP_NET_ADMIN capability.
> 
> However, the operation to be performed is not decided from the DCB message
> type, but from the DCB command. Thus DCB_CMD_*_GET commands are used for
> reading DCB objects, the corresponding SET and DEL commands are used for
> manipulation.
> 
> The assumption is that set-like commands will be sent via an RTM_SETDCB
> message, and get-like ones via RTM_GETDCB. However, this assumption is not
> enforced.
> 
> It is therefore possible to manipulate DCB objects without CAP_NET_ADMIN
> capability by sending the corresponding command in an RTM_GETDCB message.
> That is a bug. Fix it by validating the type of the request message against
> the type used for the response.
> 
> Fixes: 2f90b8657ec9 ("ixgbe: this patch adds support for DCB to the kernel and ixgbe driver")
> Signed-off-by: Petr Machata <me@pmachata.org>

Applied, thanks!
diff mbox series

Patch

diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index 084e159a12ba..7d49b6fd6cef 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -1765,6 +1765,8 @@  static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
 	fn = &reply_funcs[dcb->cmd];
 	if (!fn->cb)
 		return -EOPNOTSUPP;
+	if (fn->type != nlh->nlmsg_type)
+		return -EPERM;
 
 	if (!tb[DCB_ATTR_IFNAME])
 		return -EINVAL;