From patchwork Fri Aug 26 15:25:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 101931 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp412206qga; Fri, 26 Aug 2016 08:29:01 -0700 (PDT) X-Received: by 10.66.216.69 with SMTP id oo5mr6966578pac.155.1472225341154; Fri, 26 Aug 2016 08:29:01 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yp6si21699224pac.253.2016.08.26.08.29.01; Fri, 26 Aug 2016 08:29:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752855AbcHZP2m (ORCPT + 4 others); Fri, 26 Aug 2016 11:28:42 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:49923 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751584AbcHZP2k (ORCPT ); Fri, 26 Aug 2016 11:28:40 -0400 Received: from wuerfel.lan. ([176.0.135.42]) by mrelayeu.kundenserver.de (mreue005) with ESMTPA (Nemesis) id 0LqpCY-1b9Aws0SwM-00eM1x; Fri, 26 Aug 2016 17:26:56 +0200 From: Arnd Bergmann To: linux-kernel@vger.kernel.org Cc: Linus Torvalds , Arnd Bergmann , Hadar Hen Zion , Jiri Pirko , "David S . Miller" , netdev@vger.kernel.org Subject: [PATCH 4/5] net_sched: fix use of uninitialized ethertype variable in cls_flower Date: Fri, 26 Aug 2016 17:25:45 +0200 Message-Id: <20160826152546.604384-5-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160826152546.604384-1-arnd@arndb.de> References: <20160826152546.604384-1-arnd@arndb.de> X-Provags-ID: V03:K0:XM3PnCWMThejU6AsjZRdb4x8QDoWrdrAL/zaHsjgvs6rvA6PmY2 /5t+nNIqUx7HxUjC8br0wBXejfaMn1kagAHPV6gZMR0eSTnrlw1QKSbV1CTimpMtqyMLt1r P8JbKmVyBbgPgN3xMdDaVPVpWKhG4+vDhm16F54TFNQbxoRjxkOsRI+HJm8SAOtBEAyFilF q9v3eijJqBV5WPofvbpPg== X-UI-Out-Filterresults: notjunk:1; V01:K0:ils/9vcfPGk=:Kd9LF8VNDq4Eg9iUJEdX0c uEwwUnNoyEyRlfncIt6Lz0eBNBCWzFJAzqzweeIO1zH6yJDubWw59HubWskT5tez6zkfRqnwk xuCf6hpnRHpMWHL5CHiz7N70M1Yb4FqYagu4l9IpQ9e0kwtcGWMn1zBGzUD5OyIhVe78+b59m nnO7rHN/C8OJpCz/5nKPyWA9NW2woDKQEwHTzRkluUdXucZtZano74e/6/SouY2OcPrBwJNkZ Z4cEJQJIPNnK/AVFIPapR+cjEG5nQTFpCGMjqXKfrhcpB31XU5gjhi9x/hbrwyiRQIc2Lb9wx vxuEpH0OjAy7l8DRXnnua97wPXohRCuHbmc8ejs8LInPqUmK5D0k1Rw7fWyrRq/L9N+qTaBSa Ap5pk2ZanH+48dYlz+AfW5oAglU/KyjgEctWIvblDvX4vhj7tzBRyA7Ie7qWHSTN23KpXGfJm IiD0VfMAKk9vsqnwa3yjycS/6udq0b4MopP/cBbXafXGQQJ8ZCX9DRSsSyS3w2H83/vXhmp/v qTpbeYe9+q8djwwhzvQ9Dr1zGCZYoCCO8uc9y0NfmbMOWYqI72VBd0YJMJG+MbT7RyIHMbw5p 2L2Izb++uIXMKhyxWuruBOYRz6lZQJed+hsfqHS6XKqvP++Wx24NmYfC1tvimlATGlDDSrCp7 KqBGaKrz32V3m/dx44tYnWBfChRXvuxf5QH/UwC4mu8ggoKaf7/Fd8KxqqTJ24vWa4rk= Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The addition of VLAN support caused a possible use of uninitialized data if we encounter a zero TCA_FLOWER_KEY_ETH_TYPE key, as pointed out by "gcc -Wmaybe-uninitialized": net/sched/cls_flower.c: In function 'fl_change': net/sched/cls_flower.c:366:22: error: 'ethertype' may be used uninitialized in this function [-Werror=maybe-uninitialized] This changes the code to only set the ethertype field if it was nonzero, as before the patch. Signed-off-by: Arnd Bergmann Fixes: 9399ae9a6cb2 ("net_sched: flower: Add vlan support") Cc: Hadar Hen Zion Cc: Jiri Pirko --- Cc: David S. Miller Cc: netdev@vger.kernel.org net/sched/cls_flower.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) -- 2.9.0 diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index 532ab6751343..cf9ad5b50889 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -353,18 +353,19 @@ static int fl_set_key(struct net *net, struct nlattr **tb, mask->eth.src, TCA_FLOWER_KEY_ETH_SRC_MASK, sizeof(key->eth.src)); - if (tb[TCA_FLOWER_KEY_ETH_TYPE]) + if (tb[TCA_FLOWER_KEY_ETH_TYPE]) { ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_ETH_TYPE]); - if (ethertype == htons(ETH_P_8021Q)) { - fl_set_key_vlan(tb, &key->vlan, &mask->vlan); - fl_set_key_val(tb, &key->basic.n_proto, - TCA_FLOWER_KEY_VLAN_ETH_TYPE, - &mask->basic.n_proto, TCA_FLOWER_UNSPEC, - sizeof(key->basic.n_proto)); - } else { - key->basic.n_proto = ethertype; - mask->basic.n_proto = cpu_to_be16(~0); + if (ethertype == htons(ETH_P_8021Q)) { + fl_set_key_vlan(tb, &key->vlan, &mask->vlan); + fl_set_key_val(tb, &key->basic.n_proto, + TCA_FLOWER_KEY_VLAN_ETH_TYPE, + &mask->basic.n_proto, TCA_FLOWER_UNSPEC, + sizeof(key->basic.n_proto)); + } else { + key->basic.n_proto = ethertype; + mask->basic.n_proto = cpu_to_be16(~0); + } } if (key->basic.n_proto == htons(ETH_P_IP) ||