From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ff7YNnchMmgKVjIAWB0awg (envelope-from ) for ; Sat, 24 May 2025 15:43:51 -0400 Received: by simark.ca (Postfix, from userid 112) id C9AF51E11C; Sat, 24 May 2025 15:43:51 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-9.0 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 852C61E102 for ; Sat, 24 May 2025 15:43:48 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 12C9C385C6FF for ; Sat, 24 May 2025 19:43:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12C9C385C6FF Received: from mailout2.rbg.tum.de (mailout2.rbg.tum.de [131.159.0.202]) by sourceware.org (Postfix) with ESMTPS id 617F43858D26 for ; Sat, 24 May 2025 19:43:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 617F43858D26 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sec.in.tum.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sec.in.tum.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 617F43858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=131.159.0.202 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748115796; cv=none; b=FRi+bCHIhpB3X4RHdGy1iIpMBoz1BCgEuldjhTEZYYDSRYdiysefzUb9yBCnuK83DFbj0j6zHBtwrWtWojdCCxif4DKpV9bswBPhKbEyovwAwmt++86/5hK46eRfNLO5LFs1NBRMm6crLJVcCxRKIv2aG1De1JZsLcFMrQofWVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748115796; c=relaxed/simple; bh=PeIQqK0g4eW98PksV8zqtLpneGpNbSgx3xzS3n4ZjFA=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=F34BGFARwexIpLtb6HXnIKV3MxIM9qXHMrP8ptj/SCvexvhWYYTBPtKYZDbA00kP3NvnTEPxf4mnyBZJYz5CqeXFVCsWk/8bQoW+eiqi7X2t0LJJedu5gpkp8geL1BGCeHMGginF0pBu1CiSTJj8Gu2FD8s7B8hzz5OofyuqWOY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 617F43858D26 Received: from mailrelay1.rbg.tum.de (mailrelay1.in.tum.de [131.159.254.14]) by mailout2.rbg.tum.de (Postfix) with ESMTPS id D73DC4C023A; Sat, 24 May 2025 21:43:13 +0200 (CEST) Received: by mailrelay1.rbg.tum.de (Postfix, from userid 112) id D35DC10B; Sat, 24 May 2025 21:43:13 +0200 (CEST) Received: from mailrelay1.rbg.tum.de (localhost [127.0.0.1]) by mailrelay1.rbg.tum.de (Postfix) with ESMTP id 7928F10A; Sat, 24 May 2025 21:43:09 +0200 (CEST) Received: from services.sec.in.tum.de (services.sec.in.tum.de [131.159.50.242]) by mailrelay1.rbg.tum.de (Postfix) with ESMTPS id 74B7E104; Sat, 24 May 2025 21:43:09 +0200 (CEST) Received: from [192.168.178.35] (ipbcc3e067.dynamic.kabel-deutschland.de [188.195.224.103]) by services.sec.in.tum.de (Postfix) with ESMTPSA id 4A79A100CE80E; Sat, 24 May 2025 21:43:09 +0200 (CEST) Message-ID: <73be8b96-3a2a-4e64-885e-76f7b7ed6be1@sec.in.tum.de> Date: Sat, 24 May 2025 21:43:08 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2][PR GDB/32956] gdb: implement linux namespace support for fileio_stat To: Andrew Burgess , gdb-patches@sourceware.org References: <20250511150113.3163767-1-kilger@sec.in.tum.de> <20250511150113.3163767-2-kilger@sec.in.tum.de> <87y0umgub1.fsf@redhat.com> Content-Language: en-US From: Fabian Kilger Autocrypt: addr=kilger@sec.in.tum.de; keydata= xjMEYHltfxYJKwYBBAHaRw8BAQdA7mzpLUfZIcIiMjdx+GBa8RuqZdMp/MUEpu4PDTb2YwXN JEZhYmlhbiBLaWxnZXIgPGtpbGdlckBzZWMuaW4udHVtLmRlPsKLBBMWCAAzFiEETPRi+vRL aNymGJvYr2lqRpshfmkFAmB5bX8CGwMFCwkIBwIGFQgJCgsCBRYCAwEAAAoJEK9pakabIX5p CzcA/ivCFRRbxJfpiwOzV5CvflcHPNN2LmCxSBlcrBpliBhWAP43PcAtWheftijoLpcwy3nD 0TVTDRrJY/hRkKDbvmrWCM44BGB5bX8SCisGAQQBl1UBBQEBB0BtYlZed2qkwQWmV+MaUhC7 8XgZI0ezLuU2nr8bocqXCAMBCAfCeAQYFggAIBYhBEz0Yvr0S2jcphib2K9pakabIX5pBQJg eW1/AhsMAAoJEK9pakabIX5pUNQA/juajzwCYdtbo+sXQUlZufPiPwLiPr6LuJBNZwL6Olbm AQDvyu6h+X9K2gzgLviiNEmcCAddwynvjXiLt3c+oir7AA== In-Reply-To: <87y0umgub1.fsf@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------7eSvEQmIIYza7D4hOXwu07gj" X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --------------7eSvEQmIIYza7D4hOXwu07gj Content-Type: multipart/mixed; boundary="------------beoV5onL0lWEhN2dmAGUBqQf"; protected-headers="v1" From: Fabian Kilger To: Andrew Burgess , gdb-patches@sourceware.org Message-ID: <73be8b96-3a2a-4e64-885e-76f7b7ed6be1@sec.in.tum.de> Subject: Re: [PATCH 1/2][PR GDB/32956] gdb: implement linux namespace support for fileio_stat References: <20250511150113.3163767-1-kilger@sec.in.tum.de> <20250511150113.3163767-2-kilger@sec.in.tum.de> <87y0umgub1.fsf@redhat.com> In-Reply-To: <87y0umgub1.fsf@redhat.com> --------------beoV5onL0lWEhN2dmAGUBqQf Content-Type: multipart/mixed; boundary="------------IVENLCM5RPr0I11EAGpDwJnR" --------------IVENLCM5RPr0I11EAGpDwJnR Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Andrew, you're right, I'm directly using GDB and wasn't aware of that gdbserver module. I'll be adding it to the patch for v2. Best, Fabian On 5/24/25 12:46, Andrew Burgess wrote: > Fabian Kilger writes: >=20 >> The new algorithm to look for a build-id-based debug file >> (introduced by commit 22836ca88591ac7efacf06d5b6db191763fd8aba) >> makes use of fileio_stat. As fileio_stat was not supported by >> linux-namespace.c, all stat calls would be performed on the host >> and not inside the namespace >> >> --- >> gdb/linux-nat.c | 14 ++++++++ >> gdb/linux-nat.h | 3 ++ >> gdb/nat/linux-namespaces.c | 71 +++++++++++++++++++++++++++++++++++++= + >> gdb/nat/linux-namespaces.h | 6 ++++ >=20 > Thinking about this some more, I realised that this is missing the > gdbserver related changes. >=20 > If you search in the gdbserver/ directory for how multifs_readlink is > used then this will give a pretty good idea for how a new multifs_stat > should be added. >=20 > For manual testing things will be pretty similar to testing GDB. On th= e > same host as your container, but outside of the container, start > gdbserver: >=20 > $ gdbserver --multi --once :54321 >=20 > Then on the same host, start GDB, and within GDB: >=20 > (gdb) target extended-remote :54321 > (gdb) attach PID >=20 > I'm assuming that currently you are just attaching directly from GDB to= > a process within the container? >=20 > Thanks, > Andrew >=20 >> 4 files changed, 94 insertions(+) >> >> diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c >> index 3f252370c7b..478a7977c4d 100644 >> --- a/gdb/linux-nat.c >> +++ b/gdb/linux-nat.c >> @@ -4585,6 +4585,20 @@ linux_nat_target::fileio_open (struct inferior = *inf, const char *filename, >> return fd; >> } >> =20 >> +/* Implementation of to_fileio_stat. */ >> +int >> +linux_nat_target::fileio_stat (struct inferior *inf, const char *file= name, >> + struct stat *sb, fileio_error *target_errno) >> +{ >> + int r =3D linux_mntns_stat (linux_nat_fileio_pid_of (inf), >> + filename, sb); >> + >> + if (r =3D=3D -1) >> + *target_errno =3D host_to_fileio_error (errno); >> + >> + return r; >> +} >> + >> /* Implementation of to_fileio_readlink. */ >> =20 >> std::optional >> diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h >> index b630b858e34..42d1ec142b3 100644 >> --- a/gdb/linux-nat.h >> +++ b/gdb/linux-nat.h >> @@ -108,6 +108,9 @@ class linux_nat_target : public inf_ptrace_target >> const char *filename, >> fileio_error *target_errno) override; >> =20 >> + int fileio_stat (struct inferior *inf, const char *filename, >> + struct stat *sb, fileio_error *target_errno) override; >> + >> int fileio_unlink (struct inferior *inf, >> const char *filename, >> fileio_error *target_errno) override; >> diff --git a/gdb/nat/linux-namespaces.c b/gdb/nat/linux-namespaces.c >> index 19a05eec905..aa74e9df950 100644 >> --- a/gdb/nat/linux-namespaces.c >> +++ b/gdb/nat/linux-namespaces.c >> @@ -233,6 +233,12 @@ enum mnsh_msg_type >> MNSH_RET_INT. */ >> MNSH_REQ_SETNS, >> =20 >> + /* A request that the helper call stat. The single >> + argument (the filename) should be passed in BUF, and >> + should include a terminating NUL character. The helper >> + should respond with a MNSH_RET_INTSTR. */ >> + MNSH_REQ_STAT, >> + >> /* A request that the helper call open. Arguments should >> be passed in BUF, INT1 and INT2. The filename (in BUF) >> should include a terminating NUL character. The helper >> @@ -283,6 +289,10 @@ mnsh_debug_print_message (enum mnsh_msg_type type= , >> debug_printf ("ERROR"); >> break; >> =20 >> + case MNSH_REQ_STAT: >> + debug_printf ("STAT"); >> + break; >> + >> case MNSH_REQ_SETNS: >> debug_printf ("SETNS"); >> break; >> @@ -514,6 +524,20 @@ mnsh_handle_setns (int sock, int fd, int nstype) >> return mnsh_return_int (sock, result, errno); >> } >> =20 >> + >> +/* Handle a MNSH_REQ_STAT message. Must be async-signal-safe. */ >> + >> +static ssize_t >> +mnsh_handle_stat(int sock, const char *filename) >> +{ >> + struct stat sb; >> + int stat_ok =3D stat(filename, &sb); >> + >> + return mnsh_return_intstr(sock, stat_ok, &sb, >> + stat_ok =3D=3D -1 ? 0 : sizeof (sb), >> + errno); >> +} >> + >> /* Handle a MNSH_REQ_OPEN message. Must be async-signal-safe. */ >> =20 >> static ssize_t >> @@ -574,6 +598,11 @@ mnsh_main (int sock) >> response =3D mnsh_handle_setns (sock, fd, int1); >> break; >> =20 >> + case MNSH_REQ_STAT: >> + if (size > 0 && buf[size - 1] =3D=3D '\0') >> + response =3D mnsh_handle_stat(sock, buf); >> + break; >> + >> case MNSH_REQ_OPEN: >> if (size > 0 && buf[size - 1] =3D=3D '\0') >> response =3D mnsh_handle_open (sock, buf, int1, int2); >> @@ -765,6 +794,10 @@ mnsh_maybe_mourn_peer (void) >> mnsh_send_message (helper->sock, MNSH_REQ_OPEN, -1, flags, mode, \ >> filename, strlen (filename) + 1) >> =20 >> +#define mnsh_send_stat(helper, filename) \ >> + mnsh_send_message (helper->sock, MNSH_REQ_STAT, -1, 0, 0, \ >> + filename, strlen (filename) + 1) >> + >> #define mnsh_send_unlink(helper, filename) \ >> mnsh_send_message (helper->sock, MNSH_REQ_UNLINK, -1, 0, 0, \ >> filename, strlen (filename) + 1) >> @@ -945,6 +978,44 @@ linux_mntns_access_fs (pid_t pid) >> return MNSH_FS_HELPER; >> } >> =20 >> + >> +/* See nat/linux-namespaces.h. */ >> +int >> +linux_mntns_stat (pid_t pid, const char *filename, >> + struct stat *sb) >> +{ >> + enum mnsh_fs_code access =3D linux_mntns_access_fs (pid); >> + struct linux_mnsh *helper; >> + int stat_ok, error; >> + ssize_t size; >> + >> + if (access =3D=3D MNSH_FS_ERROR) >> + return -1; >> + >> + if (access =3D=3D MNSH_FS_DIRECT) >> + return stat(filename, sb); >> + >> + gdb_assert (access =3D=3D MNSH_FS_HELPER); >> + >> + helper =3D linux_mntns_get_helper (); >> + >> + size =3D mnsh_send_stat (helper, filename); >> + if (size < 0) >> + return -1; >> + >> + size =3D mnsh_recv_intstr (helper, &stat_ok, &error, sb, sizeof (*s= b)); >> + >> + if (size < 0) >> + { >> + stat_ok =3D -1; >> + errno =3D error; >> + } >> + else >> + gdb_assert (stat_ok =3D=3D -1 || size =3D=3D sizeof (*sb)); >> + >> + return stat_ok; >> +} >> + >> /* See nat/linux-namespaces.h. */ >> =20 >> int >> diff --git a/gdb/nat/linux-namespaces.h b/gdb/nat/linux-namespaces.h >> index 4327292950b..825cb27eb2d 100644 >> --- a/gdb/nat/linux-namespaces.h >> +++ b/gdb/nat/linux-namespaces.h >> @@ -58,6 +58,12 @@ enum linux_ns_type >> =20 >> extern int linux_ns_same (pid_t pid, enum linux_ns_type type); >> =20 >> +/* Like stat(2), but in the mount namespace of process >> + PID. */ >> + >> +extern int linux_mntns_stat (pid_t pid, const char *filename, >> + struct stat *sb); >> + >> /* Like gdb_open_cloexec, but in the mount namespace of process >> PID. */ >> =20 >> --=20 >> 2.49.0 >=20 --=20 Fabian Kilger, M.Sc. Wissenschaftlicher Mitarbeiter Technische Universit=C3=A4t M=C3=BCnchen TUM School of Computation, Information and Technology Chair of IT Security Boltzmannstra=C3=9Fe 3 85748 Garching (bei M=C3=BCnchen) Tel. +49 (0)89 289-18587 Fax +49 (0)89 289-18579 kilger@sec.in.tum.de www.sec.in.tum.de --------------IVENLCM5RPr0I11EAGpDwJnR Content-Type: application/pgp-keys; name="OpenPGP_0xAF696A469B217E69.asc" Content-Disposition: attachment; filename="OpenPGP_0xAF696A469B217E69.asc" Content-Description: OpenPGP public key Content-Transfer-Encoding: quoted-printable -----BEGIN PGP PUBLIC KEY BLOCK----- xjMEYHltfxYJKwYBBAHaRw8BAQdA7mzpLUfZIcIiMjdx+GBa8RuqZdMp/MUEpu4P DTb2YwXNJEZhYmlhbiBLaWxnZXIgPGtpbGdlckBzZWMuaW4udHVtLmRlPsKLBBMW CAAzFiEETPRi+vRLaNymGJvYr2lqRpshfmkFAmB5bX8CGwMFCwkIBwIGFQgJCgsC BRYCAwEAAAoJEK9pakabIX5pCzcA/ivCFRRbxJfpiwOzV5CvflcHPNN2LmCxSBlc rBpliBhWAP43PcAtWheftijoLpcwy3nD0TVTDRrJY/hRkKDbvmrWCM44BGB5bX8S CisGAQQBl1UBBQEBB0BtYlZed2qkwQWmV+MaUhC78XgZI0ezLuU2nr8bocqXCAMB CAfCeAQYFggAIBYhBEz0Yvr0S2jcphib2K9pakabIX5pBQJgeW1/AhsMAAoJEK9p akabIX5pUNQA/juajzwCYdtbo+sXQUlZufPiPwLiPr6LuJBNZwL6OlbmAQDvyu6h +X9K2gzgLviiNEmcCAddwynvjXiLt3c+oir7AA=3D=3D =3DVdeZ -----END PGP PUBLIC KEY BLOCK----- --------------IVENLCM5RPr0I11EAGpDwJnR-- --------------beoV5onL0lWEhN2dmAGUBqQf-- --------------7eSvEQmIIYza7D4hOXwu07gj Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature.asc" -----BEGIN PGP SIGNATURE----- wnsEABYIACMWIQRM9GL69Eto3KYYm9ivaWpGmyF+aQUCaDIhTAUDAAAAAAAKCRCvaWpGmyF+aVQ5 APsEeey+/3Qm9zClMYRnzzLpBqxuQPu/Mmz5jle7tZjp1wEAn/2zRL6s4URqbFHxFxN9KEv9PZay y0BQ1KRvcVmfwQo= =dbIe -----END PGP SIGNATURE----- --------------7eSvEQmIIYza7D4hOXwu07gj--