From patchwork Mon Mar 25 12:40:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 161090 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3918719jan; Mon, 25 Mar 2019 05:41:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqww7XOdvJwP4pokHah7SJZcdbCSGS8w0ssPgb+Uf9Gq2u3xVwBnqaBrnNRSN/sUlXDu5dKB X-Received: by 2002:a17:902:2888:: with SMTP id f8mr25355565plb.244.1553517680429; Mon, 25 Mar 2019 05:41:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553517680; cv=none; d=google.com; s=arc-20160816; b=DfraRtYBq/uCrRgEuXH9wvMvmR02rnfpPS3xgO6GcRw2taXBtyp4zi0INLyRpVHj2r TV32JpMMzzGqF4cc0Ss+ONiWdEkxssxJhN8Nc3sKwlLBhvPse7Jq6YVzV9k7vJDsi57T PFgEjPiImkIENku5dBC1VhwlKKZX72r1uFiyF9J3zPN8CyIB+jSA97vm0XRYJ7iFPaG+ f846LPLNODwlkWuSYtMlN3jqZQS7nfB7Rc44PwBd+Smhmb/a6L/VG52GGbTn8nl7B4aC ol1olGwB/79GaRcSF+XUbUQkYVTupHHRcSx8PcuEQgWiUYHLzTigdUklYiU3mMEWFOqs 9vBg== 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 :message-id:date:subject:cc:to:from; bh=27b492uhun2lj1UP0RSYwCQyDkZvDQlitLULIIQpWmk=; b=vcI7p3bDVSOzJChJPwr2AZ3XI98PguZvFkKq4jn7FsJE58wNSBjIx98AWhZbqd9s/e XZAVNvHSzea/7FQ1disTONcixi4/C/U/TSnuSso5OToxi8nBZ64waXElbJK38g6icIdC ouVz7iHtAJCbrRXcuzhxUgQTRbqR04kbw+gUnfoYXyUsL20wzyqWW+eYrdW4T4PJ5l8O IGoglg/XrUafWWdUTC1TCkAMUGTkqR/LpVcc248K0sVj4448XC69Hi8xnTtoiVBGlMFW 4oIYm9gO6O85hb1G53IcoLz0wDvxnjwMFHCq68ZaOuNNW7eyY/xeROBw3MuHWgSKbqL7 EBgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w14si13799565plq.262.2019.03.25.05.41.20; Mon, 25 Mar 2019 05:41:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731095AbfCYMlS (ORCPT + 31 others); Mon, 25 Mar 2019 08:41:18 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:55033 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730858AbfCYMlS (ORCPT ); Mon, 25 Mar 2019 08:41:18 -0400 Received: from wuerfel.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPA (Nemesis) id 1N1x2P-1gxUuA43GT-012Ijd; Mon, 25 Mar 2019 13:40:52 +0100 From: Arnd Bergmann To: Paul Moore , Stephen Smalley , Eric Paris Cc: Arnd Bergmann , selinux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] selinux: avoid uninitialized variable warning Date: Mon, 25 Mar 2019 13:40:45 +0100 Message-Id: <20190325124050.1285877-1-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 MIME-Version: 1.0 X-Provags-ID: V03:K1:9d/9dFgDs3t5g2S63jy6hB9rb1mMw//XjPFUuJMgOZtS2X9jGru iHn4ZHXT6INzgI9AE6VWLRVgCnpeKGxNyYwvmagYfOVaIeUy575LKola77DX+SDR47USV89 Bsoll2kbjbrf0/JfGOCAmPR1lIwSQKLtJJ+OUAIUazqKJAnHcGb8JdzhQhhJkO5oom1KQwo nlptQoluEqZKd2PaKMGTw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:GBkGklooK8Y=:B9rIAgfjV2Ai+K/CsjDT4v 7asOU5LWS1XlLLUu70poQ8dlA9FgjDZO1uoAEIHlLJVzjkqoQ+KOmbvt2pk3wnVJFMKu8aR+W cvNf8PRyQN6oN/l6XR4Az+RuLYz5yAKJEd0xi05hI5V3tYbReJNJVAoJ0Ij5KZxLyBTwDeH70 5aOZu3fYNj08NsaBM4T3M4s3NbbuVyL5a2aaOTvwNc6XP0CZkmh7IbCPc0DdAjqaJEIMy36j2 AwIkx8WnjEhCmfPnUiYvstkGGov4IAO0fSs90S0T4adCkGGLog21XHoCsXuQZZiVZDY0V+Cym zcGJ8c5L/3VfO5sZH13dSitBTjFHoE0vUaVgzNeYH/mVRFIZlud9pHfHaGluadoWbd6eT0s8g gyifq/daM984dSruwQgn/ppJftYTbLMZu7W/P4XK21XFt8KBYxappB9PuW1M7o09HmDIXwXOa RD/4Zt57SrzEv29LtbPZ03WsZdW5PKAZQeQLdIzaaMJsEIrMzAPYYa3ETVukaqDidhk7nuH5E jcae9riKvQw2M2gEWi/5KkzwEDWpVsEwUWcN7/waPdEoXATKLk+ar8raYsfhsSuJnd9pat1/f veAKJ7WPuu/uKDFtEplvCKMMic0nQl3fMps0hKojpKc0Z672tgfNCu7T9CVGzV8oGmzDqHje2 TNHXRIchyNAtQ39AUNrI04slDwSJpfWpShU5FiHE7jsElIbCUBkngmvuky8lv0mZBv3wDvcxu YD6pTh9/jhlcBtdXY0djTUE9BAGSCz7rf+x5BQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org clang correctly points out a code path that would lead to an uninitialized variable use: security/selinux/netlabel.c:310:6: error: variable 'addr' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] if (ip_hdr(skb)->version == 4) { ^~~~~~~~~~~~~~~~~~~~~~~~~ security/selinux/netlabel.c:322:40: note: uninitialized use occurs here rc = netlbl_conn_setattr(ep->base.sk, addr, &secattr); ^~~~ security/selinux/netlabel.c:310:2: note: remove the 'if' if its condition is always true if (ip_hdr(skb)->version == 4) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ security/selinux/netlabel.c:291:23: note: initialize the variable 'addr' to silence this warning struct sockaddr *addr; ^ = NULL This is probably harmless since we should not see ipv6 packets of CONFIG_IPV6 is disabled, but it's better to rearrange the code so this cannot happen. Link: https://lore.kernel.org/patchwork/patch/1053663/ Signed-off-by: Arnd Bergmann --- v2: revise after discussing with Paul Moore --- security/selinux/netlabel.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) -- 2.20.0 diff --git a/security/selinux/netlabel.c b/security/selinux/netlabel.c index 186e727b737b..fb4351733450 100644 --- a/security/selinux/netlabel.c +++ b/security/selinux/netlabel.c @@ -288,11 +288,8 @@ int selinux_netlbl_sctp_assoc_request(struct sctp_endpoint *ep, int rc; struct netlbl_lsm_secattr secattr; struct sk_security_struct *sksec = ep->base.sk->sk_security; - struct sockaddr *addr; struct sockaddr_in addr4; -#if IS_ENABLED(CONFIG_IPV6) struct sockaddr_in6 addr6; -#endif if (ep->base.sk->sk_family != PF_INET && ep->base.sk->sk_family != PF_INET6) @@ -310,16 +307,15 @@ int selinux_netlbl_sctp_assoc_request(struct sctp_endpoint *ep, if (ip_hdr(skb)->version == 4) { addr4.sin_family = AF_INET; addr4.sin_addr.s_addr = ip_hdr(skb)->saddr; - addr = (struct sockaddr *)&addr4; -#if IS_ENABLED(CONFIG_IPV6) - } else { + rc = netlbl_conn_setattr(ep->base.sk, (void*)&addr4, &secattr); + } else if (IS_ENABLED(CONFIG_IPV6)) { addr6.sin6_family = AF_INET6; addr6.sin6_addr = ipv6_hdr(skb)->saddr; - addr = (struct sockaddr *)&addr6; -#endif + rc = netlbl_conn_setattr(ep->base.sk, (void*)&addr6, &secattr); + } else { + rc = -EAFNOSUPPORT; } - rc = netlbl_conn_setattr(ep->base.sk, addr, &secattr); if (rc == 0) sksec->nlbl_state = NLBL_LABELED;