Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8819741ybi; Tue, 23 Jul 2019 16:00:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxvB1Vp3KAWfvwJYNkdWlQ8lxVqQDIxlzkrJEGWZIxcf7YU/yHPxypanqehyzPBdiLsMP2 X-Received: by 2002:a17:902:1e9:: with SMTP id b96mr83394071plb.277.1563922851287; Tue, 23 Jul 2019 16:00:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563922851; cv=none; d=google.com; s=arc-20160816; b=r/XX4oxzn1UNsyAR6u67l4ZysJNt0yxkpkF82/ToIpKTo0mcc1QXiztCdL6CUKGtfh cCPu84g7mdI0brKk51fIKAFkopiEhtabchMBZ+GgY4tS+5Zh60zogYJligtnBND0usbT orCi3Z8Kwe/qyRVw9VJJnpaurM5QXbKq4nLhaBup+LWHiY4likAiIghC2ntH5hSwxPGO 4Bw4Khb3aw8p+UlQkrN1VHTk42b5z8if+uAxHj9cMIfH/UkQ72ZVgiroCRy+yV99mYZy ixVYQsiIkdwUMMkQJW+BvTVDR9+zSkm56MWkUC9ArZGLEWBnIajUrBvtL0yXzEL3YI3x Y4UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=saeXoWECyoKEtOOoPI6Phu+Fdq1kw47VGG1GsjtWjEI=; b=H/B9UAHmaLL2WSJ/9qmU1QFgixPuwoZPPiURVXspDGWSPwOJH5k9Ncrv3Gw1sAF1it txi1x9nKnjgwWIJojaxloSbDFlihQXLA+noKlSp6ITWIEAKz+KJ0Qwn7ZX3L5mYZc4g0 DtOYKDAJemSzz+vz5SxC/zSKIfzzHEeO616GzIvakLXMQulK1pRcoDweMtRmrIOxXlRo DjCPMXFnaFnpU4NhQjPod95XL/gIjLih4OJ/1PlLtrY0yprb5l0793AOomVYqXR2ENQc AW4YsepOt1IpNy/fvEGqNlUPg7EFJBpzaIYezyGLueMwKXoGRP5qA2ZtRp4XbEvrSVCc SMuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=RZwUL4gm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z5si12339452pgj.213.2019.07.23.16.00.34; Tue, 23 Jul 2019 16:00:51 -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=@samsung.com header.s=mail20170921 header.b=RZwUL4gm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389476AbfGWMIU (ORCPT + 99 others); Tue, 23 Jul 2019 08:08:20 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:34405 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387744AbfGWMIT (ORCPT ); Tue, 23 Jul 2019 08:08:19 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20190723120817euoutp01134d59506aad29a1c30de829d273b8a5~0B_-3g-yu1942219422euoutp019 for ; Tue, 23 Jul 2019 12:08:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20190723120817euoutp01134d59506aad29a1c30de829d273b8a5~0B_-3g-yu1942219422euoutp019 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1563883697; bh=saeXoWECyoKEtOOoPI6Phu+Fdq1kw47VGG1GsjtWjEI=; h=From:To:Cc:Subject:Date:References:From; b=RZwUL4gmUIGVRyMPmFrrF7vR9Xy12Wy7k+3r29Pjf38rlj1L0ucHZ40JZW8QM1SMr ugp0EaxqzlmrPCGKWshqZ8yUDLjQwISLpu0qMyGOn9z6CyuHIcTZ2JFnBbtx7OHkU/ 9ynofT0OO+gnGQUz6TINqmjKaM1QAMKFK8OLxQl0= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20190723120816eucas1p1136e3b1061351f354b732e7946ff4555~0B__bWh721147711477eucas1p1H; Tue, 23 Jul 2019 12:08:16 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id CF.6A.04377.0B8F63D5; Tue, 23 Jul 2019 13:08:16 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20190723120815eucas1p21027b1ab47daba7ebb3a885bf869be8a~0B_9xDh1f2866228662eucas1p2c; Tue, 23 Jul 2019 12:08:15 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20190723120815eusmtrp26b6947496f450fbf458446b45efdea4a~0B_9mgU8D0548605486eusmtrp2S; Tue, 23 Jul 2019 12:08:15 +0000 (GMT) X-AuditID: cbfec7f4-12dff70000001119-85-5d36f8b05c0f Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 26.DF.04146.FA8F63D5; Tue, 23 Jul 2019 13:08:15 +0100 (BST) Received: from imaximets.rnd.samsung.ru (unknown [106.109.129.180]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20190723120814eusmtip2a569cc20adc435617bf5b5c96b33792f~0B_855vIj0299402994eusmtip2f; Tue, 23 Jul 2019 12:08:14 +0000 (GMT) From: Ilya Maximets To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, xdp-newbies@vger.kernel.org, "David S. Miller" , Magnus Karlsson , Alexei Starovoitov , Daniel Borkmann , Ilya Maximets Subject: [PATCH bpf] libbpf: fix using uninitialized ioctl results Date: Tue, 23 Jul 2019 15:08:10 +0300 Message-Id: <20190723120810.28801-1-i.maximets@samsung.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDIsWRmVeSWpSXmKPExsWy7djP87obfpjFGjyexGLx5edtdovPR46z WSxe+I3ZYs75FhaLK+0/2S0u75rDZrHi0Al2i2MLxCy29+9jdOD02LLyJpPH4j0vmTy6blxi 9ti0qpPNo2/LKkaPz5vkAtiiuGxSUnMyy1KL9O0SuDKad3YzFlwVrnj66hxLA2OzQBcjJ4eE gInEtunX2LoYuTiEBFYwSlw82QPlfGGUmPRmDTOE85lRYs30k+wwLb2/F7JCJJYzSiz5eYoJ wvnBKLF541xWkCo2AR2JU6uPMILYIgJSEh93bGcHKWIWWMok8X7hFqAlHBzCAk4SH3bwg9Sw CKhK9C5sYAGxeQWsJVb/u8cCsU1eYvWGA2BnSAi8ZpPYvvYeI0TCRWLK3IVMELawxKvjW6DO k5H4v3M+VLxe4n7LS0aI5g5GiemH/kEl7CW2vD7HDnIEs4CmxPpd+iCmhICjRFOLN4TJJ3Hj rSBIMTOQOWnbdGaIMK9ER5sQxAwVid8HlzND2FISN999hjrAQ2I71B4hgViJjc/+s09glJuF sGoBI+MqRvHU0uLc9NRio7zUcr3ixNzi0rx0veT83E2MwDRx+t/xLzsYd/1JOsQowMGoxMO7 YY9prBBrYllxZe4hRgkOZiUR3sAGs1gh3pTEyqrUovz4otKc1OJDjNIcLErivNUMD6KFBNIT S1KzU1MLUotg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b1ab47daba7ebb3a885bf869be8a X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20190723120815eucas1p21027b1ab47daba7ebb3a885bf869be8a X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20190723120815eucas1p21027b1ab47daba7ebb3a885bf869be8a References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org '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 --- tools/lib/bpf/xsk.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c index 5007b5d4fd2c..c4f912dc30f9 100644 --- a/tools/lib/bpf/xsk.c +++ b/tools/lib/bpf/xsk.c @@ -317,7 +317,7 @@ 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 ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS }; struct ifreq ifr; int fd, err, ret; @@ -325,7 +325,7 @@ static int xsk_get_max_queues(struct xsk_socket *xsk) if (fd < 0) return -errno; - channels.cmd = ETHTOOL_GCHANNELS; + memset(&ifr, 0, sizeof(ifr)); ifr.ifr_data = (void *)&channels; strncpy(ifr.ifr_name, xsk->ifname, IFNAMSIZ - 1); ifr.ifr_name[IFNAMSIZ - 1] = '\0'; @@ -335,7 +335,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.17.1