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 71E0D20ED; Sat, 12 Sep 2026 15:04:48 +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=1789225489; cv=none; b=HsvMn3e9DRiyc1DunrK+bUKDIvP1odon/OTTtTA2wLIUHoktlQwOgIvpi4ebiQySTlsvma6K+YGAnKtZA2JUkqMRi2MhHC3eeGLxNmpGLJgEMA//IYRJv2SmHvWnw2peqBEn+3+BfYNuKgnIWMzSFe6wIpTUAkxf+XtLiiSz7NE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789225489; c=relaxed/simple; bh=No6wtxbg+Q/lnLf8to0ieQQlQUyoZIQoD/S1+s29Ups=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X3eV4nWY+/GGcZDdaEBzoL060L1MU8Tc+Vt5FAVOpY1jsmhXDjlFU8gEjMspsM/X6et29tdmZ9s2ZcQN2tjOSicZpw4cI/dxN8SSWmaHh02LPHkRwxstuYPuDkwDxSR7wgCdgWyiUxEHOjhe5BHmyogoHWm4zm09VNrlBSbWy2c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xbzEkqxl; 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="xbzEkqxl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76D7D1F000FF; Sat, 12 Sep 2026 15:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789225488; bh=sDir0SIdOAne2XGAm5BxyBSEcoQJsfHj1UH9neH2s5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xbzEkqxljb/jRHNrF/OEQ3CfMH7E4dTlj1SiA+BIgeH0hV2JIcjwTzlVZKAeE3OYS RMBb4FgxqOmzVJUaLld5MsPaprdX+0mAc0ssdx6d3M5I51fGFr+4+/fIRDSB0FelEP M82vx5/jfCgzNONUHVBaa7l/IT1nkwcdPWwDT2Fc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yuan Chen , Andrii Nakryiko , Sasha Levin Subject: [PATCH 6.6 1208/1424] bpftool: Fix double close in map dump Date: Sat, 12 Sep 2026 09:00:40 +0200 Message-ID: <20260912065634.338116105@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065607.279695368@linuxfoundation.org> References: <20260912065607.279695368@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.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yuan Chen [ Upstream commit 259d60f5bfa41056fe01cbf2ba3f6f0331865a16 ] map_dump() closes the map fd in its error path, and do_dump() then closes the same fd again after a successful dump. Closing an already closed fd leaves errno set to EBADF, which poisons later errno checks such as the batch file read check in do_batch(). Let do_dump() own the fd and remove the close from map_dump(). The same double-close pattern exists in do_show_subset(): both show_map_close_json() and show_map_close_plain() already close the fd, so drop the extra close() there as well. Also propagate the error when bpf_map_get_info_by_fd() fails on a subsequent map in do_dump(): set err = -1 before breaking out of the loop, so a later failure is not silently hidden after an earlier iteration succeeded. Fixes: 99f9863a0c45f ("bpftool: Match maps by name") Signed-off-by: Yuan Chen Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20260810142224.2907373-2-chenyuan_fl@163.com Signed-off-by: Sasha Levin --- tools/bpf/bpftool/map.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c index 6edea36fc6375..a89a0cdb90e21 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c @@ -659,8 +659,6 @@ static int do_show_subset(int argc, char **argv) show_map_close_json(fds[i], &info); else show_map_close_plain(fds[i], &info); - - close(fds[i]); } if (json_output && nb_fds > 1) jsonw_end_array(json_wtr); /* root array */ @@ -892,7 +890,6 @@ map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr, exit_free: free(key); free(value); - close(fd); free_map_kv_btf(btf); return err; @@ -941,6 +938,7 @@ static int do_dump(int argc, char **argv) for (i = 0; i < nb_fds; i++) { if (bpf_map_get_info_by_fd(fds[i], &info, &len)) { p_err("can't get map info: %s", strerror(errno)); + err = -1; break; } err = map_dump(fds[i], &info, wtr, nb_fds > 1); -- 2.53.0