queue_userspace_packet() decides from OVS_DP_F_UNALIGNED whether to copy the packet with skb_zerocopy(), and pad_packet() reads the same field again after the copy. A concurrent OVS_DP_CMD_SET can clear the bit between the two reads, so the copy leaves a nonlinear skb and the padding calls skb_put_zero() on it. skb_put() asserts that the skb is linear, so the kernel oopses, and a host built with panic_on_oops goes down. OVS_DP_CMD_SET needs CAP_NET_ADMIN, which a user namespace that owns a network namespace provides, so the window is reachable without privileges on the host. Read the field once and pass that value to pad_packet(). Fixes: aea0bb4f8ee5 ("openvswitch: Pad OVS_PACKET_ATTR_PACKET if linear copy was performed") Cc: stable@vger.kernel.org Signed-off-by: Minxi Hou --- v6: split out of the fix v5 carried as one patch. Reading the field once is an older and separate crash, so it stands as its own patch with its own Fixes: tag (aea0bb4f8ee5, the commit that added the second read). net/openvswitch/datapath.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index b2a0b09fd4a5..96baa2488c26 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -439,9 +439,9 @@ static size_t upcall_msg_size(const struct dp_upcall_info *upcall_info, return size; } -static void pad_packet(struct datapath *dp, struct sk_buff *skb) +static void pad_packet(struct sk_buff *skb, u32 features) { - if (!(dp->user_features & OVS_DP_F_UNALIGNED)) { + if (!(features & OVS_DP_F_UNALIGNED)) { size_t plen = NLA_ALIGN(skb->len) - skb->len; if (plen > 0) @@ -461,6 +461,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, size_t msg_size; size_t skb_len; unsigned int hlen; + u32 features; int err, dp_ifindex; u64 hash; @@ -494,11 +495,18 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, (err = skb_csum_hwoffload_help(skb, 0))) goto out; + /* A concurrent change to the features can land between the head room + * decision below and the padding after the copy, which would pad a + * nonlinear skb and trip SKB_LINEAR_ASSERT. Read the field once and use + * that value for both. + */ + features = READ_ONCE(dp->user_features); + /* Older versions of OVS user space enforce alignment of the last * Netlink attribute to NLA_ALIGNTO which would require extensive * padding logic. Only perform zerocopy if padding is not required. */ - if (dp->user_features & OVS_DP_F_UNALIGNED) + if (features & OVS_DP_F_UNALIGNED) hlen = min(skb_zerocopy_headlen(skb), cutlen); else hlen = skb_len; @@ -598,7 +606,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, goto out; /* Pad OVS_PACKET_ATTR_PACKET if linear copy was performed */ - pad_packet(dp, user_skb); + pad_packet(user_skb, features); ((struct nlmsghdr *) user_skb->data)->nlmsg_len = user_skb->len; -- 2.56.1