From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5711D46EF84; Tue, 21 Jul 2026 19:26:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784662004; cv=none; b=uHh2U6g7s0T7tIKSjBboK82mH4pP8ZKaeylO0VvD6z0ubd4TkelTsi6S3hWdNSSmSSsws77OSjSVhYvWmpmV/XPd57HLYlOAYbmUwWuwtERezbPynNo0CiKee5jU0fre8ko5kSOa5Zl+M9KzkCUGvHKeyAj+1GPjkgs30RPS+Bc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784662004; c=relaxed/simple; bh=BqbOdZ79J7BkuioOD34H7muDsAf9DD92uBKzX9Y04J4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AjhfbcJOLMP93buILWe9fs5T37FvWfTAkZQfnID3iFkiXTyygyKrxY6ADqBOxdwXgzXH4Bm3vZ/igz86bjDs/X0rSnpfQsgKjPjnQAutOLDAhtJcVxyVVNevYuyDpoASXxRIQM+KwV9sk1+XCjgPCUKjvRmKn/5A85ZLoJJ/IZ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Pkrxch1P; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Pkrxch1P" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B02B81F000E9; Tue, 21 Jul 2026 19:26:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784662003; bh=N6gNcXoq0FIG18ZoK9/Bo24XveoJ8/V4wdmnDurPmZg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Pkrxch1P5ERG6NLfrWRxT9AMSo4/IcrQnJfuN2zpuuPUKWQZPoLTaXlmi5bd5XI1k ZWzcnSEC4fr5LnIBBgDf36WmMHv+zvvRgBLU/z3s1LwQRdQ58xM+GOCMs8ycOP8Lmd jYcC/NTmX4/5ENYXeDVLTTZYnJbTbBuOMlplAHLc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Woojin Ji , Andrii Nakryiko , Leon Hwang , Yonghong Song , Quentin Monnet , Sasha Levin Subject: [PATCH 6.12 0228/1276] bpftool: Use libbpf error code for flow dissector query Date: Tue, 21 Jul 2026 17:11:11 +0200 Message-ID: <20260721152451.193674246@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152446.065700225@linuxfoundation.org> References: <20260721152446.065700225@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Woojin Ji [ Upstream commit 8a7f2bff2165e53595d1e91c160b340f978c0ab7 ] bpf_prog_query() returns a negative errno on failure. query_flow_dissector() currently closes the namespace fd and then reads errno to decide whether -EINVAL means that the running kernel does not support flow dissector queries. That errno check controls behavior, not just diagnostics: -EINVAL is handled as a non-fatal old-kernel case, while any other error makes bpftool net fail. The namespace fd is opened read-only, so close() is not expected to commonly fail in normal use. Still, the BPF_PROG_QUERY error is already available in err, and reading errno after an intervening close() is fragile. If close() does change errno, the compatibility branch may be based on close()'s error instead of the BPF_PROG_QUERY result. This was reproduced with an LD_PRELOAD fault injector that forced BPF_PROG_QUERY for BPF_FLOW_DISSECTOR to fail with EINVAL and then forced close() on the netns fd to fail with EIO. The unpatched bpftool reported "can't query prog: Input/output error". With this change, the same injected failure is handled as the intended non-fatal EINVAL compatibility case. Use the libbpf-returned error code instead. Keep the existing errno reset in the non-fatal path to preserve batch mode behavior. The success path is unchanged. Fixes: 7f0c57fec80f ("bpftool: show flow_dissector attachment status") Signed-off-by: Woojin Ji Signed-off-by: Andrii Nakryiko Acked-by: Leon Hwang Acked-by: Yonghong Song Acked-by: Quentin Monnet Link: https://lore.kernel.org/bpf/20260603003339.33791-1-random6.xyz@gmail.com Assisted-by: ChatGPT:gpt-5.5 Signed-off-by: Sasha Levin --- tools/bpf/bpftool/net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/bpf/bpftool/net.c b/tools/bpf/bpftool/net.c index 587403a19af3a6..89e2adcccf13fa 100644 --- a/tools/bpf/bpftool/net.c +++ b/tools/bpf/bpftool/net.c @@ -603,14 +603,14 @@ static int query_flow_dissector(struct bpf_attach_info *attach_info) &attach_flags, prog_ids, &prog_cnt); close(fd); if (err) { - if (errno == EINVAL) { + if (err == -EINVAL) { /* Older kernel's don't support querying * flow dissector programs. */ errno = 0; return 0; } - p_err("can't query prog: %s", strerror(errno)); + p_err("can't query prog: %s", strerror(-err)); return -1; } -- 2.53.0