From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 8ILcI6lRSWjydwkAWB0awg (envelope-from ) for ; Wed, 11 Jun 2025 05:51:37 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=I11rM9Tw; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8E6271E11C; Wed, 11 Jun 2025 05:51:37 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-10.1 required=5.0 tests=ARC_SIGNED,ARC_VALID, BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, 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 3040B1E089 for ; Wed, 11 Jun 2025 05:51:34 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CCBED385841C for ; Wed, 11 Jun 2025 09:51:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCBED385841C Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=I11rM9Tw Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id A37503858D39 for ; Wed, 11 Jun 2025 09:47:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A37503858D39 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A37503858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749635269; cv=none; b=Lu8qsbTlAdnzF+W5MHh6taQ1TNRu/HJKdNh3S21kyhN45ijj24R1p2ETIeORUuBOa+ajVCHYaDAM9PbeGA7Ctf3NnlHkYDIL3at9dCIay4KlhD7lA/WUdmawFxdCf9kqD+ezHME8PGRmqj8zyOiiH+EnnoJCC1OAE55cTV5GTU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749635269; c=relaxed/simple; bh=wljuhSJUWW46q8R67UHwjiKTBCKLkDYJayTbwvtrZpE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tg3qxX5TXqzT9aFpgp2o1dI1IjRndT3YmKrAqrNzgTjc4xvxtVMRIG2Cl7KzGBA2iH9CsBmPjmDc+QdBvR3MBS2+FAf36rvZkvbdlxlN9CiuT2pPh2vyqSdEbQGzjSwTCqCtkCZ740iTNNTc3rnSj31+lRrG6SvGd/go4p+XoHM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A37503858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749635269; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FNBUmHiisLWZSlOJjxCgeEMpbsJTTFxOgQqvXRInF+E=; b=I11rM9TwcjpWS0GM+XxYBbnYe58DGS1/weKhOu8TbRVWrMDUAOzcEyI5rWgTlI34iz7kR2 BJc/4RfZj7+9TdjjbPy9SXTT87pp9+WYezaUTzzsEt5C0y3LfmKc2gTVk8RaxhXMfxd+om DfIFLeRvg0vm9agHwd6yR0OC1BPzrUQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-696-h48fexNwPPa8XHjKBFwrIQ-1; Wed, 11 Jun 2025 05:47:48 -0400 X-MC-Unique: h48fexNwPPa8XHjKBFwrIQ-1 X-Mimecast-MFC-AGG-ID: h48fexNwPPa8XHjKBFwrIQ_1749635267 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-451d30992bcso50765635e9.2 for ; Wed, 11 Jun 2025 02:47:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749635267; x=1750240067; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:to:from:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=zS1LfkBB+4nTlCHM2jhsHq1U4tJH+d477zmlJif78FI=; b=s4Umq11CzUHBkbfai3uHs8psnWUBgoKZzwPFtHVTiUnTdrXQ/xsfbaQKScRihsnKqk AmbYveptJqqYzhlPhhE8TSbiFtTg1x60JPcGR1Trdzn9jNL/3fcFW33Rb34SgHnujv3F nREEVKIXbasilvINfgB25QiMsuWXGKqQAA7N/1W25BNJHeGyj5hRURccGuwydsb83z+J zFkhjiAhRSwJIqZKjCYIWmESP3FDUHAnbiCuW8qvfnJUgxo+kbpokakFW1F3LaOggHuT /gVQth469EIXSy7HvIDO4OJOT7FwxV9xeUT9KgCVGRYnGwwN32WffSpEiX1TIAMRr0uK evxQ== X-Forwarded-Encrypted: i=1; AJvYcCV55rAN/dVJflIPU01MBIstOAf6pWy1bSXdcdVerzam/nhztgKXwx6ljSCPl9B9YQOwunOAZCxPagQk6g==@sourceware.org X-Gm-Message-State: AOJu0Yxf9vZOwEHsyMtcOxEGOZMGP1dKxaPo1iFDEsh2QyjUyzBWTpMs wa5T+O+UAlVRuJK0hbB4X630SeXPA9OLRMe6EKEihNOG0GMoJWE1z6ufvi3rgeIhhCSuzoo5lgj iIjuseJmpxek6MCOdO0Vch9Ct6Ad8QppioU4fkGwRSoLiieyEN6Pkd5af0PSZ4x750FP2KEk= X-Gm-Gg: ASbGnctt/+roSNmXAOqUhlIZgVskysKiaF5ewiBQ1x72lCL1VUlLv9qwYhUdY6y6Clv f4az/EEVLWyIK6bk1ahw7tOZ/paJmRKtudJvuf0oeps4QMVyVU4JwvkMPh4Q9O7UZF1jFTeSWWx GfZqd8zDFvZClp574nI8QpYHTVKaBH0MYX+0h1TJvbO2n0aiaZAorX98BfRQlavAzUxQ/2Zec2F M1lnOAIwMhEcYVFStJYYwumWJ9K06/8gdtmAsSZsoblRFG+mJ1+gw3TiGFZmCVvxEs1D75S0OO/ BC9P8J4zjgMoF3IWEgNmyTdlyQDAh4Opr5o66NqXVh20Xw8= X-Received: by 2002:a05:600c:3511:b0:441:b19c:96fe with SMTP id 5b1f17b1804b1-45324882d3amr26296225e9.10.1749635266684; Wed, 11 Jun 2025 02:47:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGndl935wJXLZA+VK1+P92QqfUMAL8Xnlg/gOUIvyjONPQJM0wJPNujpNXs4LF/5t16DuDoWw== X-Received: by 2002:a05:600c:3511:b0:441:b19c:96fe with SMTP id 5b1f17b1804b1-45324882d3amr26295895e9.10.1749635266183; Wed, 11 Jun 2025 02:47:46 -0700 (PDT) Received: from localhost (75.226.159.143.dyn.plus.net. [143.159.226.75]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244d10asm14991776f8f.67.2025.06.11.02.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 02:47:45 -0700 (PDT) From: Andrew Burgess To: Fabian Kilger , gdb-patches@sourceware.org Subject: Re: [PATCH 1/2][PR GDB/32956] gdb: implement linux namespace support for fileio_stat In-Reply-To: <784e0c86-f879-46d5-8631-702e6ae611bc@sec.in.tum.de> References: <20250511150113.3163767-1-kilger@sec.in.tum.de> <20250511150113.3163767-2-kilger@sec.in.tum.de> <87y0umgub1.fsf@redhat.com> <73be8b96-3a2a-4e64-885e-76f7b7ed6be1@sec.in.tum.de> <784e0c86-f879-46d5-8631-702e6ae611bc@sec.in.tum.de> Date: Wed, 11 Jun 2025 10:47:45 +0100 Message-ID: <87zfeehany.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: P5kosz_RidY0vMQxrizyDt8eC15gkNr9p2nt_Ao9jrI_1749635267 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 Fabian Kilger writes: > While looking at it, I've noticed all implementations of stat functions > actually use lstat and not stat. This maybe should be modified in the > namespace case as well and I'll be changing this for v2. However, I > could not directly find a rationale behind why *_stat functions call > lstat instead. Possibly, it might make sense renaming the > target_fileio_stat to target_fileio_lstat as well, though this would be > an independent change. Without digging into the history I say for sure why it's lstat over stat. I agree with you that renaming the API might make some sense, though I suspect we're really a little stuck, the remote protocol packet is called 'stat', which is unfortunate, we cannot really change that. I do agree that within the namespace code we should probably use lstat in order to be consistent. Thanks, Andrew > > Best, > Fabian > > On 5/24/25 21:43, Fabian Kilger wrote: >> Hi Andrew, >>=20 >> 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. >>=20 >> Best, >> Fabian >>=20 >> On 5/24/25 12:46, Andrew Burgess wrote: >>> Fabian Kilger writes: >>> >>>> 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 ++++ >>> >>> Thinking about this some more, I realised that this is missing the >>> gdbserver related changes. >>> >>> 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. >>> >>> 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: >>> >>> $ gdbserver --multi --once :54321 >>> >>> Then on the same host, start GDB, and within GDB: >>> >>> (gdb) target extended-remote :54321 >>> (gdb) attach PID >>> >>> I'm assuming that currently you are just attaching directly from GDB to >>> a process within the container? >>> >>> Thanks, >>> Andrew >>> >>>> 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, >>>> +=09=09=09 struct stat *sb, fileio_error *target_errno) >>>> +{ >>>> + int r =3D linux_mntns_stat (linux_nat_fileio_pid_of (inf), >>>> +=09=09=09 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 >>>> =09=09 const char *filename, >>>> =09=09 fileio_error *target_errno) override; >>>> =20 >>>> + int fileio_stat (struct inferior *inf, const char *filename, >>>> +=09=09 struct stat *sb, fileio_error *target_errno) override; >>>> + >>>> int fileio_unlink (struct inferior *inf, >>>> =09=09 const char *filename, >>>> =09=09 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, >>>> +=09=09=09 stat_ok =3D=3D -1 ? 0 : sizeof (sb), >>>> +=09=09=09 errno); >>>> +} >>>> + >>>> /* Handle a MNSH_REQ_OPEN message. Must be async-signal-safe. */ >>>> =20 >>>> static ssize_t >>>> @@ -574,6 +598,11 @@ mnsh_main (int sock) >>>> =09=09response =3D mnsh_handle_setns (sock, fd, int1); >>>> =09 break; >>>> =20 >>>> +=09 case MNSH_REQ_STAT: >>>> +=09 if (size > 0 && buf[size - 1] =3D=3D '\0') >>>> +=09=09response =3D mnsh_handle_stat(sock, buf); >>>> +=09 break; >>>> + >>>> =09 case MNSH_REQ_OPEN: >>>> =09 if (size > 0 && buf[size - 1] =3D=3D '\0') >>>> =09=09response =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, \ >>>> =09=09 filename, strlen (filename) + 1) >>>> =20 >>>> +#define mnsh_send_stat(helper, filename) \ >>>> + mnsh_send_message (helper->sock, MNSH_REQ_STAT, -1, 0, 0, \ >>>> +=09=09 filename, strlen (filename) + 1) >>>> + >>>> #define mnsh_send_unlink(helper, filename) \ >>>> mnsh_send_message (helper->sock, MNSH_REQ_UNLINK, -1, 0, 0, \ >>>> =09=09 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, >>>> +=09=09 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, >>>> +=09=09=09 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 > -----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-----