From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
To: steffen.klassert@secunet.com, davem@davemloft.net
Cc: netdev@vger.kernel.org,
Nicolas Dichtel <nicolas.dichtel@6wind.com>,
Julien Floret <julien.floret@6wind.com>
Subject: [PATCH ipsec v2 1/4] xfrm interface: avoid corruption on changelink
Date: Mon, 15 Jul 2019 12:00:20 +0200 [thread overview]
Message-ID: <20190715100023.8475-2-nicolas.dichtel@6wind.com> (raw)
In-Reply-To: <20190715100023.8475-1-nicolas.dichtel@6wind.com>
The new parameters must not be stored in the netdev_priv() before
validation, it may corrupt the interface. Note also that if data is NULL,
only a memset() is done.
$ ip link add xfrm1 type xfrm dev lo if_id 1
$ ip link add xfrm2 type xfrm dev lo if_id 2
$ ip link set xfrm1 type xfrm dev lo if_id 2
RTNETLINK answers: File exists
$ ip -d link list dev xfrm1
5: xfrm1@lo: <NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/none 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 minmtu 68 maxmtu 1500
xfrm if_id 0x2 addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
=> "if_id 0x2"
Fixes: f203b76d7809 ("xfrm: Add virtual xfrm interfaces")
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Tested-by: Julien Floret <julien.floret@6wind.com>
---
net/xfrm/xfrm_interface.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/net/xfrm/xfrm_interface.c b/net/xfrm/xfrm_interface.c
index 74868f9d81fb..2310dc9e35c2 100644
--- a/net/xfrm/xfrm_interface.c
+++ b/net/xfrm/xfrm_interface.c
@@ -671,12 +671,12 @@ static int xfrmi_changelink(struct net_device *dev, struct nlattr *tb[],
struct nlattr *data[],
struct netlink_ext_ack *extack)
{
- struct xfrm_if *xi = netdev_priv(dev);
struct net *net = dev_net(dev);
+ struct xfrm_if_parms p;
+ struct xfrm_if *xi;
- xfrmi_netlink_parms(data, &xi->p);
-
- xi = xfrmi_locate(net, &xi->p);
+ xfrmi_netlink_parms(data, &p);
+ xi = xfrmi_locate(net, &p);
if (!xi) {
xi = netdev_priv(dev);
} else {
@@ -684,7 +684,7 @@ static int xfrmi_changelink(struct net_device *dev, struct nlattr *tb[],
return -EEXIST;
}
- return xfrmi_update(xi, &xi->p);
+ return xfrmi_update(xi, &p);
}
static size_t xfrmi_get_size(const struct net_device *dev)
--
2.21.0
next prev parent reply other threads:[~2019-07-15 10:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-10 7:45 [PATCH ipsec 0/2] xfrm interface: bug fix on changelink Nicolas Dichtel
2019-07-10 7:45 ` [PATCH ipsec 1/2] xfrm interface: avoid corruption " Nicolas Dichtel
2019-07-10 7:45 ` [PATCH ipsec 2/2] xfrm interface: ifname may be wrong in logs Nicolas Dichtel
2019-07-15 9:52 ` [PATCH ipsec 0/2] xfrm interface: bug fix on changelink Nicolas Dichtel
2019-07-15 10:00 ` [PATCH ipsec v2 0/4] xfrm interface: bugs fixes Nicolas Dichtel
2019-07-15 10:00 ` Nicolas Dichtel [this message]
2019-07-15 10:00 ` [PATCH ipsec v2 2/4] xfrm interface: ifname may be wrong in logs Nicolas Dichtel
2019-07-15 10:00 ` [PATCH ipsec v2 3/4] xfrm interface: fix list corruption for x-netns Nicolas Dichtel
2019-07-15 10:00 ` [PATCH ipsec v2 4/4] xfrm interface: fix management of phydev Nicolas Dichtel
2019-07-18 7:37 ` [PATCH ipsec v2 0/4] xfrm interface: bugs fixes Steffen Klassert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190715100023.8475-2-nicolas.dichtel@6wind.com \
--to=nicolas.dichtel@6wind.com \
--cc=davem@davemloft.net \
--cc=julien.floret@6wind.com \
--cc=netdev@vger.kernel.org \
--cc=steffen.klassert@secunet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).