Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5222324ybl; Tue, 27 Aug 2019 01:03:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwx+o+W2wak9IGgLzT5WbW7xLzFHD1r6wPpiUd34rbk72jrd5paH4/TRGGdzb7v7+KiUZdY X-Received: by 2002:a63:4a51:: with SMTP id j17mr19980702pgl.284.1566893006797; Tue, 27 Aug 2019 01:03:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566893006; cv=none; d=google.com; s=arc-20160816; b=cwk18MLJsgm6//OTuVEXzdXt7beA+eRQ8UN4ijBj1dRlUJ9IirWIj4sb2d2qey0Odt Zf0vxsdJpMmTYyNaF4DyLT/loAbhKrrwiKkpLRuP0pNy4gMUTEHzd5DgIKirDy/d28X8 8AdrVMAWSbcVOFk2eW4ErrsDpGt5bMvzotcTkub/jdJHATsTterSfjDDvVJmQS1F1ovL 6Xvh12AcV1UPO3UTwjI/+57nmSUtrAGBTWrUy4l4xjQgfzHiMKvc8qnBGb8Ha+utnNTf 5eZ4BxSlzY2r/NYzR4B6GqZJMyC/g8LH4UTB53hzVIL856UgQqTG0HMFaQfcaolhNN52 As9A== 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=gQbqqwa/HHUPI844bccb5Uo3SOjvS2bZczeAs7uQjtA=; b=XlkZtw0mc3OLYCLfp3xfLn85hd6LlrXhAZp4+B0N017zWlCQ0PhvZv82c6hsCkyxE5 feQlOdWm3Tkvo1Q3naSst/aH2UfUM45vbI4Jb+mlNIa882Zv8kVC7ssungonlawJ/z/9 lwmpqIelYpuXzRI0ph6g7mnb4obTDpuPJ9it82A6qJFJLB1iC7QfFPLLmjxm5sJvAL6S dSkDpKCkq6Fvnq8dw9IwFtHWsYVz9tLMxhp6AklKQwa5Y9v9BLAK6y9/0Qv9ihiZJep5 dwdtUPzNZ2o5nSGPTFB2yC2LuaZVyXq6Wqk7nKLOtG440wDIhrWjVCSj5rV2iQxMpZPI oMrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=H98oh5wU; 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 q15si11083352pgt.150.2019.08.27.01.03.11; Tue, 27 Aug 2019 01:03:26 -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; dkim=pass header.i=@kernel.org header.s=default header.b=H98oh5wU; 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 S1731544AbfH0IAi (ORCPT + 99 others); Tue, 27 Aug 2019 04:00:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:55656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731534AbfH0IAg (ORCPT ); Tue, 27 Aug 2019 04:00:36 -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 5998D217F5; Tue, 27 Aug 2019 08:00:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566892834; bh=/zzZA9U0vrszr+exayCqiwcHv1WS9ZwywmCOOuoNULQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H98oh5wUvli8zyGKyXeK8sv+nn0giu8oDgLiYEdsNOdgaQmptmnHssFQqkDuVtaoD x/HEk88exjmuZT38Hk55Scyqk5LXYoKTHxOpSeb+oB8SF/pZwZklvZ3ICO8Y0E6K2Y ixVlZbaf2afgY/BeJ4wyXhFzlYu46wViVbHx5jcg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Magnus Karlsson , Ilya Maximets , Andrii Nakryiko , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.2 031/162] libbpf: fix using uninitialized ioctl results Date: Tue, 27 Aug 2019 09:49:19 +0200 Message-Id: <20190827072739.375906444@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072738.093683223@linuxfoundation.org> References: <20190827072738.093683223@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 [ Upstream commit decb705e01a5d325c9876b9674043cde4b54f0db ] 'channels.max_combined' initialized only on ioctl success and errno is only valid on ioctl failure. The code doesn't produce any runtime issues, but makes memory sanitizers angry: Conditional jump or move depends on uninitialised value(s) at 0x55C056F: xsk_get_max_queues (xsk.c:336) by 0x55C05B2: xsk_create_bpf_maps (xsk.c:354) by 0x55C089F: xsk_setup_xdp_prog (xsk.c:447) by 0x55C0E57: xsk_socket__create (xsk.c:601) Uninitialised value was created by a stack allocation at 0x55C04CD: xsk_get_max_queues (xsk.c:318) Additionally fixed warning on uninitialized bytes in ioctl arguments: Syscall param ioctl(SIOCETHTOOL) points to uninitialised byte(s) at 0x648D45B: ioctl (in /usr/lib64/libc-2.28.so) by 0x55C0546: xsk_get_max_queues (xsk.c:330) by 0x55C05B2: xsk_create_bpf_maps (xsk.c:354) by 0x55C089F: xsk_setup_xdp_prog (xsk.c:447) by 0x55C0E57: xsk_socket__create (xsk.c:601) Address 0x1ffefff378 is on thread 1's stack in frame #1, created by xsk_get_max_queues (xsk.c:318) Uninitialised value was created by a stack allocation at 0x55C04CD: xsk_get_max_queues (xsk.c:318) CC: Magnus Karlsson Fixes: 1cad07884239 ("libbpf: add support for using AF_XDP sockets") Signed-off-by: Ilya Maximets Acked-by: Andrii Nakryiko Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- tools/lib/bpf/xsk.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c index ca272c5b67f47..8e03b65830da0 100644 --- a/tools/lib/bpf/xsk.c +++ b/tools/lib/bpf/xsk.c @@ -327,15 +327,14 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk) static int xsk_get_max_queues(struct xsk_socket *xsk) { - struct ethtool_channels channels; - struct ifreq ifr; + struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS }; + struct ifreq ifr = {}; int fd, err, ret; fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) return -errno; - channels.cmd = ETHTOOL_GCHANNELS; ifr.ifr_data = (void *)&channels; strncpy(ifr.ifr_name, xsk->ifname, IFNAMSIZ - 1); ifr.ifr_name[IFNAMSIZ - 1] = '\0'; @@ -345,7 +344,7 @@ static int xsk_get_max_queues(struct xsk_socket *xsk) goto out; } - if (channels.max_combined == 0 || errno == EOPNOTSUPP) + if (err || channels.max_combined == 0) /* If the device says it has no channels, then all traffic * is sent to a single stream, so max queues = 1. */ -- 2.20.1