* [PATCH net-next 0/2] Add checks for incoming packet addresses
@ 2022-02-18 4:25 Jeremy Kerr
2022-02-18 4:25 ` [PATCH net-next 1/2] mctp: replace mctp_address_ok with more fine-grained helpers Jeremy Kerr
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jeremy Kerr @ 2022-02-18 4:25 UTC (permalink / raw)
To: netdev; +Cc: David S. Miller, Jakub Kicinski, Matt Johnston
This series adds a couple of checks for valid addresses on incoming MCTP
packets. We introduce a couple of helpers in 1/2, and use them in the
ingress path in 2/2.
Cheers,
Jeremy
---
Jeremy Kerr (2):
mctp: replace mctp_address_ok with more fine-grained helpers
mctp: add address validity checking for packet receive
include/net/mctp.h | 12 +++++++++++-
net/mctp/device.c | 2 +-
net/mctp/neigh.c | 2 +-
net/mctp/route.c | 13 ++++++++++++-
4 files changed, 25 insertions(+), 4 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH net-next 1/2] mctp: replace mctp_address_ok with more fine-grained helpers 2022-02-18 4:25 [PATCH net-next 0/2] Add checks for incoming packet addresses Jeremy Kerr @ 2022-02-18 4:25 ` Jeremy Kerr 2022-02-18 4:25 ` [PATCH net-next 2/2] mctp: add address validity checking for packet receive Jeremy Kerr 2022-02-19 5:50 ` [PATCH net-next 0/2] Add checks for incoming packet addresses patchwork-bot+netdevbpf 2 siblings, 0 replies; 4+ messages in thread From: Jeremy Kerr @ 2022-02-18 4:25 UTC (permalink / raw) To: netdev; +Cc: David S. Miller, Jakub Kicinski, Matt Johnston Currently, we have mctp_address_ok(), which checks if an EID is in the "valid" range of 8-254 inclusive. However, 0 and 255 may also be valid addresses, depending on context. 0 is the NULL EID, which may be set when physical addressing is used. 255 is valid as a destination address for broadcasts. This change renames mctp_address_ok to mctp_address_unicast, and adds similar helpers for broadcast and null EIDs, which will be used in an upcoming commit. Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> --- include/net/mctp.h | 12 +++++++++++- net/mctp/device.c | 2 +- net/mctp/neigh.c | 2 +- net/mctp/route.c | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/net/mctp.h b/include/net/mctp.h index e80a4baf8379..d37268fe6825 100644 --- a/include/net/mctp.h +++ b/include/net/mctp.h @@ -40,11 +40,21 @@ struct mctp_hdr { #define MCTP_INITIAL_DEFAULT_NET 1 -static inline bool mctp_address_ok(mctp_eid_t eid) +static inline bool mctp_address_unicast(mctp_eid_t eid) { return eid >= 8 && eid < 255; } +static inline bool mctp_address_broadcast(mctp_eid_t eid) +{ + return eid == 255; +} + +static inline bool mctp_address_null(mctp_eid_t eid) +{ + return eid == 0; +} + static inline bool mctp_address_matches(mctp_eid_t match, mctp_eid_t eid) { return match == eid || match == MCTP_ADDR_ANY; diff --git a/net/mctp/device.c b/net/mctp/device.c index 02ddc0f1bd3e..9e097e61f23a 100644 --- a/net/mctp/device.c +++ b/net/mctp/device.c @@ -209,7 +209,7 @@ static int mctp_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, if (!mdev) return -ENODEV; - if (!mctp_address_ok(addr->s_addr)) + if (!mctp_address_unicast(addr->s_addr)) return -EINVAL; /* Prevent duplicates. Under RTNL so don't need to lock for reading */ diff --git a/net/mctp/neigh.c b/net/mctp/neigh.c index 6ad3e33bd4d4..ffa0f9e0983f 100644 --- a/net/mctp/neigh.c +++ b/net/mctp/neigh.c @@ -143,7 +143,7 @@ static int mctp_rtm_newneigh(struct sk_buff *skb, struct nlmsghdr *nlh, } eid = nla_get_u8(tb[NDA_DST]); - if (!mctp_address_ok(eid)) { + if (!mctp_address_unicast(eid)) { NL_SET_ERR_MSG(extack, "Invalid neighbour EID"); return -EINVAL; } diff --git a/net/mctp/route.c b/net/mctp/route.c index 0c4c56e1bd6e..6a11d78cfbab 100644 --- a/net/mctp/route.c +++ b/net/mctp/route.c @@ -962,7 +962,7 @@ static int mctp_route_add(struct mctp_dev *mdev, mctp_eid_t daddr_start, struct net *net = dev_net(mdev->dev); struct mctp_route *rt, *ert; - if (!mctp_address_ok(daddr_start)) + if (!mctp_address_unicast(daddr_start)) return -EINVAL; if (daddr_extent > 0xff || daddr_start + daddr_extent >= 255) -- 2.34.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net-next 2/2] mctp: add address validity checking for packet receive 2022-02-18 4:25 [PATCH net-next 0/2] Add checks for incoming packet addresses Jeremy Kerr 2022-02-18 4:25 ` [PATCH net-next 1/2] mctp: replace mctp_address_ok with more fine-grained helpers Jeremy Kerr @ 2022-02-18 4:25 ` Jeremy Kerr 2022-02-19 5:50 ` [PATCH net-next 0/2] Add checks for incoming packet addresses patchwork-bot+netdevbpf 2 siblings, 0 replies; 4+ messages in thread From: Jeremy Kerr @ 2022-02-18 4:25 UTC (permalink / raw) To: netdev; +Cc: David S. Miller, Jakub Kicinski, Matt Johnston This change adds some basic sanity checks for the source and dest headers of packets on initial receive. Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> --- net/mctp/route.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/net/mctp/route.c b/net/mctp/route.c index 6a11d78cfbab..fe6c8bf1ec2c 100644 --- a/net/mctp/route.c +++ b/net/mctp/route.c @@ -1092,6 +1092,17 @@ static int mctp_pkttype_receive(struct sk_buff *skb, struct net_device *dev, if (mh->ver < MCTP_VER_MIN || mh->ver > MCTP_VER_MAX) goto err_drop; + /* source must be valid unicast or null; drop reserved ranges and + * broadcast + */ + if (!(mctp_address_unicast(mh->src) || mctp_address_null(mh->src))) + goto err_drop; + + /* dest address: as above, but allow broadcast */ + if (!(mctp_address_unicast(mh->dest) || mctp_address_null(mh->dest) || + mctp_address_broadcast(mh->dest))) + goto err_drop; + /* MCTP drivers must populate halen/haddr */ if (dev->type == ARPHRD_MCTP) { cb = mctp_cb(skb); -- 2.34.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next 0/2] Add checks for incoming packet addresses 2022-02-18 4:25 [PATCH net-next 0/2] Add checks for incoming packet addresses Jeremy Kerr 2022-02-18 4:25 ` [PATCH net-next 1/2] mctp: replace mctp_address_ok with more fine-grained helpers Jeremy Kerr 2022-02-18 4:25 ` [PATCH net-next 2/2] mctp: add address validity checking for packet receive Jeremy Kerr @ 2022-02-19 5:50 ` patchwork-bot+netdevbpf 2 siblings, 0 replies; 4+ messages in thread From: patchwork-bot+netdevbpf @ 2022-02-19 5:50 UTC (permalink / raw) To: Jeremy Kerr; +Cc: netdev, davem, kuba, matt Hello: This series was applied to netdev/net-next.git (master) by Jakub Kicinski <kuba@kernel.org>: On Fri, 18 Feb 2022 12:25:52 +0800 you wrote: > This series adds a couple of checks for valid addresses on incoming MCTP > packets. We introduce a couple of helpers in 1/2, and use them in the > ingress path in 2/2. > > Cheers, > > > [...] Here is the summary with links: - [net-next,1/2] mctp: replace mctp_address_ok with more fine-grained helpers https://git.kernel.org/netdev/net-next/c/cb196b725936 - [net-next,2/2] mctp: add address validity checking for packet receive https://git.kernel.org/netdev/net-next/c/86cdfd63f25d You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-02-19 5:52 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-02-18 4:25 [PATCH net-next 0/2] Add checks for incoming packet addresses Jeremy Kerr 2022-02-18 4:25 ` [PATCH net-next 1/2] mctp: replace mctp_address_ok with more fine-grained helpers Jeremy Kerr 2022-02-18 4:25 ` [PATCH net-next 2/2] mctp: add address validity checking for packet receive Jeremy Kerr 2022-02-19 5:50 ` [PATCH net-next 0/2] Add checks for incoming packet addresses patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).