Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3320757pxf; Mon, 15 Mar 2021 07:05:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxubyggm4QIEk9JtCpd1zqBqfyM+ZWvUCb04++z8LcffeODE6bBqBEZoRoJNIUluUcYYbob X-Received: by 2002:a17:906:4a19:: with SMTP id w25mr23346003eju.180.1615817149092; Mon, 15 Mar 2021 07:05:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615817149; cv=none; d=google.com; s=arc-20160816; b=hgGxQxNsi6cN+z/DwKsXw5kC/qUj05J+IsjiuFF/935Tl1ugHkDTIpkgcHcsaRX01E LBi4+tm5UTGk4/Hd46QAHchs85EXQiHs8CyjuclZSll4LTwlpGUJWqHA0hEjJBRObmqf NaOdKeZjFdpYGj3NE2VVDuIZhQioGrjvuFnkpWH3C5gnhr8qjEtDV4wtyN5wrAZpqn7F RsPyCmaOvT1NbPlIY1FBkvcdIaRgZ8tF3f2A6lv4apfys+on+i2+SO0Jw+N7ZmB6aG0l 7hqBx60e3n9NYpxfp3vnUgGJWfT1ScrucXJCxETzsMZ9cCEPU9nGEZ/Dvlt37DW9BxiZ qNvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fGGrCYzXMMAp6ZRKQu7GKVek0l7Qvd6ArzB7OICu9a4=; b=ON4RlolfcCND/ihZ5xIgPHsemznZ7u5O2HNXcaCDhThOUstAnLiNRgv85mK+3swhb+ wGt+Ojs3AAhblOk1eDlf87Pi56UQx9ixHXT0R14BCKebSQQ29zZLbjAgu59WRr2RCwWg t9EtkI2p6pnDfFJyRR2aOEes9Sw3VGFfnxgnQSxaOXA/E7OWZUIOE+//mnWNI9UJX77r LeWJLUCb2YEv8dbrHTfifg79n1GqYEw9DnVQAKg/3x446oANekE7W5fAeMf+FxGwIozD CoSWOuCaO1F04KKdNwProkyGVHWkOh6KR2S6UjlUrTHrL3pP4wJFYNnMbP7uj6pBaslU 8bdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OzyoPmOq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n18si11003035edt.3.2021.03.15.07.05.26; Mon, 15 Mar 2021 07:05:49 -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=@linuxfoundation.org header.s=korg header.b=OzyoPmOq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234508AbhCOODq (ORCPT + 99 others); Mon, 15 Mar 2021 10:03:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:34826 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231572AbhCON5P (ORCPT ); Mon, 15 Mar 2021 09:57:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 04CE764F18; Mon, 15 Mar 2021 13:57:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816635; bh=Ov+vMxu7B3lb5UN/RgPNTqrMU4kdSUd3pJNbWAZnNKs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OzyoPmOqd3ang9+JQo2jGaCdcUY1az2ER1YBAQMgm8Fq55YKLoJKvOUwXfr+H0/Mr 58SZ+3u/admrZ1iO1fcTsxPHfWCGb/RMITW0m/ngz4DiGfLd87XRFkNwkbUVtLLrCb DEA7pHYrHlI22dlLlpkrODudTkT35okMJHOgcvoQ= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maciej Fijalkowski , Daniel Borkmann , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= Subject: [PATCH 5.11 033/306] libbpf: Clear map_info before each bpf_obj_get_info_by_fd Date: Mon, 15 Mar 2021 14:51:36 +0100 Message-Id: <20210315135508.748269654@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Maciej Fijalkowski commit 2b2aedabc44e9660f90ccf7ba1ca2706d75f411f upstream. xsk_lookup_bpf_maps, based on prog_fd, looks whether current prog has a reference to XSKMAP. BPF prog can include insns that work on various BPF maps and this is covered by iterating through map_ids. The bpf_map_info that is passed to bpf_obj_get_info_by_fd for filling needs to be cleared at each iteration, so that it doesn't contain any outdated fields and that is currently missing in the function of interest. To fix that, zero-init map_info via memset before each bpf_obj_get_info_by_fd call. Also, since the area of this code is touched, in general strcmp is considered harmful, so let's convert it to strncmp and provide the size of the array name for current map_info. While at it, do s/continue/break/ once we have found the xsks_map to terminate the search. Fixes: 5750902a6e9b ("libbpf: proper XSKMAP cleanup") Signed-off-by: Maciej Fijalkowski Signed-off-by: Daniel Borkmann Acked-by: Björn Töpel Link: https://lore.kernel.org/bpf/20210303185636.18070-4-maciej.fijalkowski@intel.com Signed-off-by: Greg Kroah-Hartman --- tools/lib/bpf/xsk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/tools/lib/bpf/xsk.c +++ b/tools/lib/bpf/xsk.c @@ -535,15 +535,16 @@ static int xsk_lookup_bpf_maps(struct xs if (fd < 0) continue; + memset(&map_info, 0, map_len); err = bpf_obj_get_info_by_fd(fd, &map_info, &map_len); if (err) { close(fd); continue; } - if (!strcmp(map_info.name, "xsks_map")) { + if (!strncmp(map_info.name, "xsks_map", sizeof(map_info.name))) { ctx->xsks_map_fd = fd; - continue; + break; } close(fd);