Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4413684pxa; Mon, 10 Aug 2020 08:31:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy22+bQA/bCo2QaImtgOZE0isoo9jt0+eh95tv4/fqARANeh+arV0tXD2ch4d4S+YTw8zfA X-Received: by 2002:a17:907:7204:: with SMTP id dr4mr21442447ejc.258.1597073495381; Mon, 10 Aug 2020 08:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597073495; cv=none; d=google.com; s=arc-20160816; b=qkKCMel0ZjBvME2cKCBM+Ai0CxC6ZELswJey/tYrrxieONIyCKi6YgUTVdG2E7+9Yi vo/oAjn/F5abFHhQKrOCCc9D+nDffAN8AOX5RoT3H0G3MWFagJ9LNoRQPyANRvUhx8Bw tqXUVpLgScqr+bypEq/nsrD9aCrl6Nvegj416f4Lw2XLFL5F7XDTn4yFMHe1fimxCi1H m/biA3uazNInM3mGbdUR2/6wXS8oATQ2OaHMrtXDqJBKSp0BwSRMzU0n4AcDBO1Lq1Ct bRNWrVti37rUFme0VgEQKT+WGAUg2WCyk3apG5paUtdPnOcEAPgKk3youCfX5P0IBgxX FzFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eHUmrYEEjLvK5JynnD5Q5Sl5x4PPMd2HHydr9hL/92Y=; b=G2PXe/OrFiVli314hzKhIuGhQ02jXX8mNQR8wusblQxzaNAjOLeZJ4pblC/097uJ/H e7y+FG83lC/0o9isgf7/G+VAtrffvR8roS1IvovbIbtZW0l1JjBjIKlSgbu/qXaH52BN /Z4lq7JBdQLBI/l3P6jUEppragi9givURUCxV8ZrZsOX/4lrGH0IV5d16OS0AX+VrMzy cW6c3JYEXzeIteSkh3gfa+/P+ykyFTgYPWIRCvFeSdQx2KZZOsLJQb9vuA7+k0l9H8h9 GnH7N9C2ZD3MbEuEF5d6FAFPfKY9bVlWtAEoYxRUKhSXqbPovBY9mF6iwc7tsyl3U0O2 r+9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dIEey57B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r25si10405806ejx.486.2020.08.10.08.31.11; Mon, 10 Aug 2020 08:31:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dIEey57B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729126AbgHJPap (ORCPT + 99 others); Mon, 10 Aug 2020 11:30:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:37700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729115AbgHJPak (ORCPT ); Mon, 10 Aug 2020 11:30:40 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1C6BC20791; Mon, 10 Aug 2020 15:30:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597073439; bh=zZFORStaZXvfpALaYEp5lJ3bO9RAW3xz5oKg83SFFtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dIEey57BkFzNjyzOPyABy/nAkDh6a+itHh8O0NgMJvgfb8Kb1O7uxmqvhYDIf2M4q Zi1/huefJU6xt1v1e/Nx6LFqIadtBA0xNJdeTiUdjjOx87O4vaVXgwTjoOgtkao298 MOB97Ui836tqJz4yej1HrGmGRkU4Ag0lZ/o7LAMw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Peilin Ye , "David S. Miller" Subject: [PATCH 4.19 40/48] openvswitch: Prevent kernel-infoleak in ovs_ct_put_key() Date: Mon, 10 Aug 2020 17:22:02 +0200 Message-Id: <20200810151806.189853359@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200810151804.199494191@linuxfoundation.org> References: <20200810151804.199494191@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peilin Ye [ Upstream commit 9aba6c5b49254d5bee927d81593ed4429e91d4ae ] 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(). Fixes: 9dd7f8907c37 ("openvswitch: Add original direction conntrack tuple to sw_flow_key.") Suggested-by: Dan Carpenter Signed-off-by: Peilin Ye Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/openvswitch/conntrack.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) --- a/net/openvswitch/conntrack.c +++ b/net/openvswitch/conntrack.c @@ -283,10 +283,6 @@ void ovs_ct_fill_key(const struct sk_buf 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) { @@ -308,24 +304,30 @@ int ovs_ct_put_key(const struct sw_flow_ 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;