* [Linux-kernel-mentees] [PATCH net] openvswitch: Prevent kernel-infoleak in ovs_ct_put_key()
@ 2020-07-31 4:48 Peilin Ye
2020-08-03 22:10 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Peilin Ye @ 2020-07-31 4:48 UTC (permalink / raw)
To: Pravin B Shelar
Cc: dev, Arnd Bergmann, linux-kernel, David S. Miller, netdev,
Jakub Kicinski, linux-kernel-mentees, Peilin Ye, Dan Carpenter
ovs_ct_put_key() is potentially copying uninitialized kernel stack memory
into socket buffers, since the compiler may leave a 3-byte hole at the end
of `struct ovs_key_ct_tuple_ipv4` and `struct ovs_key_ct_tuple_ipv6`. Fix
it by initializing `orig` with memset().
Cc: stable@vger.kernel.org
Fixes: 9dd7f8907c37 ("openvswitch: Add original direction conntrack tuple to sw_flow_key.")
Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
---
Reference: https://lwn.net/Articles/417989/
$ pahole -C "ovs_key_ct_tuple_ipv4" net/openvswitch/conntrack.o
struct ovs_key_ct_tuple_ipv4 {
__be32 ipv4_src; /* 0 4 */
__be32 ipv4_dst; /* 4 4 */
__be16 src_port; /* 8 2 */
__be16 dst_port; /* 10 2 */
__u8 ipv4_proto; /* 12 1 */
/* size: 16, cachelines: 1, members: 5 */
/* padding: 3 */
/* last cacheline: 16 bytes */
};
$ pahole -C "ovs_key_ct_tuple_ipv6" net/openvswitch/conntrack.o
struct ovs_key_ct_tuple_ipv6 {
__be32 ipv6_src[4]; /* 0 16 */
__be32 ipv6_dst[4]; /* 16 16 */
__be16 src_port; /* 32 2 */
__be16 dst_port; /* 34 2 */
__u8 ipv6_proto; /* 36 1 */
/* size: 40, cachelines: 1, members: 5 */
/* padding: 3 */
/* last cacheline: 40 bytes */
};
net/openvswitch/conntrack.c | 38 +++++++++++++++++++------------------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index 4340f25fe390..98d393e70de3 100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -276,10 +276,6 @@ void ovs_ct_fill_key(const struct sk_buff *skb, struct sw_flow_key *key)
ovs_ct_update_key(skb, NULL, key, false, false);
}
-#define IN6_ADDR_INITIALIZER(ADDR) \
- { (ADDR).s6_addr32[0], (ADDR).s6_addr32[1], \
- (ADDR).s6_addr32[2], (ADDR).s6_addr32[3] }
-
int ovs_ct_put_key(const struct sw_flow_key *swkey,
const struct sw_flow_key *output, struct sk_buff *skb)
{
@@ -301,24 +297,30 @@ int ovs_ct_put_key(const struct sw_flow_key *swkey,
if (swkey->ct_orig_proto) {
if (swkey->eth.type == htons(ETH_P_IP)) {
- struct ovs_key_ct_tuple_ipv4 orig = {
- output->ipv4.ct_orig.src,
- output->ipv4.ct_orig.dst,
- output->ct.orig_tp.src,
- output->ct.orig_tp.dst,
- output->ct_orig_proto,
- };
+ struct ovs_key_ct_tuple_ipv4 orig;
+
+ memset(&orig, 0, sizeof(orig));
+ orig.ipv4_src = output->ipv4.ct_orig.src;
+ orig.ipv4_dst = output->ipv4.ct_orig.dst;
+ orig.src_port = output->ct.orig_tp.src;
+ orig.dst_port = output->ct.orig_tp.dst;
+ orig.ipv4_proto = output->ct_orig_proto;
+
if (nla_put(skb, OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV4,
sizeof(orig), &orig))
return -EMSGSIZE;
} else if (swkey->eth.type == htons(ETH_P_IPV6)) {
- struct ovs_key_ct_tuple_ipv6 orig = {
- IN6_ADDR_INITIALIZER(output->ipv6.ct_orig.src),
- IN6_ADDR_INITIALIZER(output->ipv6.ct_orig.dst),
- output->ct.orig_tp.src,
- output->ct.orig_tp.dst,
- output->ct_orig_proto,
- };
+ struct ovs_key_ct_tuple_ipv6 orig;
+
+ memset(&orig, 0, sizeof(orig));
+ memcpy(orig.ipv6_src, output->ipv6.ct_orig.src.s6_addr32,
+ sizeof(orig.ipv6_src));
+ memcpy(orig.ipv6_dst, output->ipv6.ct_orig.dst.s6_addr32,
+ sizeof(orig.ipv6_dst));
+ orig.src_port = output->ct.orig_tp.src;
+ orig.dst_port = output->ct.orig_tp.dst;
+ orig.ipv6_proto = output->ct_orig_proto;
+
if (nla_put(skb, OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6,
sizeof(orig), &orig))
return -EMSGSIZE;
--
2.25.1
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH net] openvswitch: Prevent kernel-infoleak in ovs_ct_put_key()
2020-07-31 4:48 [Linux-kernel-mentees] [PATCH net] openvswitch: Prevent kernel-infoleak in ovs_ct_put_key() Peilin Ye
@ 2020-08-03 22:10 ` David Miller
2020-08-03 22:39 ` Peilin Ye
0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2020-08-03 22:10 UTC (permalink / raw)
To: yepeilin.cs
Cc: dev, arnd, linux-kernel, pshelar, netdev, kuba,
linux-kernel-mentees, dan.carpenter
From: Peilin Ye <yepeilin.cs@gmail.com>
Date: Fri, 31 Jul 2020 00:48:38 -0400
> ovs_ct_put_key() is potentially copying uninitialized kernel stack memory
> into socket buffers, since the compiler may leave a 3-byte hole at the end
> of `struct ovs_key_ct_tuple_ipv4` and `struct ovs_key_ct_tuple_ipv6`. Fix
> it by initializing `orig` with memset().
>
> Cc: stable@vger.kernel.org
Please don't CC: stable for networking fixes.
> Fixes: 9dd7f8907c37 ("openvswitch: Add original direction conntrack tuple to sw_flow_key.")
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
Applied and queued up for -stable, thank you.
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH net] openvswitch: Prevent kernel-infoleak in ovs_ct_put_key()
2020-08-03 22:10 ` David Miller
@ 2020-08-03 22:39 ` Peilin Ye
0 siblings, 0 replies; 3+ messages in thread
From: Peilin Ye @ 2020-08-03 22:39 UTC (permalink / raw)
To: David Miller
Cc: dev, arnd, linux-kernel, pshelar, netdev, kuba,
linux-kernel-mentees, dan.carpenter
On Mon, Aug 03, 2020 at 03:10:38PM -0700, David Miller wrote:
> From: Peilin Ye <yepeilin.cs@gmail.com>
> Date: Fri, 31 Jul 2020 00:48:38 -0400
>
> > ovs_ct_put_key() is potentially copying uninitialized kernel stack memory
> > into socket buffers, since the compiler may leave a 3-byte hole at the end
> > of `struct ovs_key_ct_tuple_ipv4` and `struct ovs_key_ct_tuple_ipv6`. Fix
> > it by initializing `orig` with memset().
> >
> > Cc: stable@vger.kernel.org
>
> Please don't CC: stable for networking fixes.
Sorry, I didn't know about that.
> > Fixes: 9dd7f8907c37 ("openvswitch: Add original direction conntrack tuple to sw_flow_key.")
> > Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
>
> Applied and queued up for -stable, thank you.
Thank you for reviewing the patch!
Peilin Ye
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-08-03 22:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-31 4:48 [Linux-kernel-mentees] [PATCH net] openvswitch: Prevent kernel-infoleak in ovs_ct_put_key() Peilin Ye
2020-08-03 22:10 ` David Miller
2020-08-03 22:39 ` Peilin Ye
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).