Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3983010pxb; Tue, 25 Jan 2022 00:38:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzoKpO8u3JyDfiwqctwVZWFIXT1T2LIF5GehAXVm7oxyCaH5oZWq6QmmKU4WCG3fK7ZFGga X-Received: by 2002:a63:2c07:: with SMTP id s7mr14370206pgs.191.1643099903922; Tue, 25 Jan 2022 00:38:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643099903; cv=none; d=google.com; s=arc-20160816; b=Q6E6HZddig0Wn8Sjl5vyFoSTjQ/MuoDRwRS+asqu039INxGRc+j2Hvxc0bhRLktVjB tV21UA9rC7sg7ej/VNkQ36ZdrP6GbEVB2ZJMlE/S9R/u63TH8cb2jHuMf2eYuyqESgxH cFvrM3K/LWKcsf4KLDqsuV1+2kxYuCun3RPh1gk1DEk5z5aRjfAD7uYuwYBN5yZqRwlD YbrtWeoBOeqkbQJw9b4SPsvBCTEx1yuIENqP+kWnj1qZK6JzS5UfjCQD9wgU3gL4GUf8 25HdmiWPa4F2eDoBff5SmfIL3Jy2CnzBJ9YnL1NHtSnMOXNvAqUgs7WaiyQxzjYSE0O6 7OPw== 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=/wdJPP2BrgAnPwMt1YJHvX9LFb+VqPIbs3taQFnTeOo=; b=x/5j2NMCvGKE3HIJhjXGdkP6PYQHz08M1UiHLuHeFFgbWGCfbVZiE1RP+bj2CwDDZY iwTayy1N7Kp5RmauYNVc7LDbvVDjP8AoCq7rCjKSfCaqpBMCZAu1AHs39/JiysvoN8JA rytEz0mIVq4Fz4sBmLQx612P9xAy8bsh3nMi1R/rrXRfOuvPcHP5hm7JpR2L/iKVXFkZ zrUPbz6hWuOPncZ/w4oELzxx5xTYv6OUIXtnOE2bDGNiFeEoSVjC3Xrizt0BoUlA5B8a 1jYtbThqaxpEZKVx4q0jpWC+3C1azWa/blv5Uv4SN7fZJjRrto8urKgFDrBfYFLJ09rq vAVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Qoz0/kz2"; 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 x37si15412788pgl.334.2022.01.25.00.38.12; Tue, 25 Jan 2022 00:38:23 -0800 (PST) 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="Qoz0/kz2"; 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 S1315403AbiAYCxU (ORCPT + 99 others); Mon, 24 Jan 2022 21:53:20 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:59310 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348762AbiAXVGs (ORCPT ); Mon, 24 Jan 2022 16:06:48 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CCED7612E9; Mon, 24 Jan 2022 21:06:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90D5CC340E5; Mon, 24 Jan 2022 21:06:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058405; bh=+VyVfYj83dZxsimPLx22dq/9IYfnUuhTlUu61BPlxBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qoz0/kz2WP2TBwb6zYSLX1IkgLR3RlvNyAllMOM+eu5VwZgTbCczTzE2BJHpTcwl5 shaUwoK5K2uqk76LaxoJWTyUOhf9U1CZ44ZILFmI0o1wc4RQY7wMQPnDAaIbvrGSap PetKoplorpSN4ScYn2AC5H2ir9Oj2P+iVwTyB5z0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.16 0279/1039] libbpf: Fix gen_loader assumption on number of programs. Date: Mon, 24 Jan 2022 19:34:28 +0100 Message-Id: <20220124184134.661928656@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: Alexei Starovoitov [ Upstream commit 259172bb6514758ce3be1610c500b51a9f44212a ] libbpf's obj->nr_programs includes static and global functions. That number could be higher than the actual number of bpf programs going be loaded by gen_loader. Passing larger nr_programs to bpf_gen__init() doesn't hurt. Those exra stack slots will stay as zero. bpf_gen__finish() needs to check that actual number of progs that gen_loader saw is less than or equal to obj->nr_programs. Fixes: ba05fd36b851 ("libbpf: Perform map fd cleanup for gen_loader in case of error") Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- tools/lib/bpf/gen_loader.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/gen_loader.c b/tools/lib/bpf/gen_loader.c index 4ac65afc99e50..737e7cbe3e547 100644 --- a/tools/lib/bpf/gen_loader.c +++ b/tools/lib/bpf/gen_loader.c @@ -371,8 +371,9 @@ int bpf_gen__finish(struct bpf_gen *gen, int nr_progs, int nr_maps) { int i; - if (nr_progs != gen->nr_progs || nr_maps != gen->nr_maps) { - pr_warn("progs/maps mismatch\n"); + if (nr_progs < gen->nr_progs || nr_maps != gen->nr_maps) { + pr_warn("nr_progs %d/%d nr_maps %d/%d mismatch\n", + nr_progs, gen->nr_progs, nr_maps, gen->nr_maps); gen->error = -EFAULT; return gen->error; } -- 2.34.1