public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Tyson Whitehead via Gdb-patches <gdb-patches@sourceware.org>,
	gdb-patches@sourceware.org
Cc: Tyson Whitehead <twhitehead@gmail.com>
Subject: Re: [PATCH] Fallback to direct access if lacking pemission for linux namespaces
Date: Wed, 20 Sep 2023 09:48:24 +0100	[thread overview]
Message-ID: <87zg1hxmav.fsf@redhat.com> (raw)
In-Reply-To: <20230919235134.2243437-1-twhitehead@gmail.com>

Tyson Whitehead via Gdb-patches <gdb-patches@sourceware.org> writes:

> The case where gdb and the target had the same path always used to
> work. Now it fails if gdb and the target are in different namespaces
> and gdb doesn't have permission to enter the target namespace.

So I just read the bug report, and I think you did a better job there of
explaining the background of why you wrote this patch.  You should
include the history in the commit message, instead of just saying that
something used to work and now fails.

> This commit causes gdb to fall back to trying direct access should
> it lack permission to enter the namespace. This way it does not
> break a case that used to work or require capabilites not required.

Out of interest, did you consider doing:

  (gdb) set sysroot

as a mechanism to solve your problem?  This feels like a better
solution to me, as this better describes your local setup.

The problem I see with your proposal is that in the case where the
namespace path _isn't_ visible to GDB, and if for some reason GDB isn't
able to setns(), then the errors the user sees will be for GDB trying to
open the namepsace path as if it were local -- which might give the
impression that GDB is doing the wrong thing.

If we are going to fall back to attempting local access (as a last
ditched effort), then we should, at the very least, emit a warning to
let the user know that we couldn't setns() and that we're trying local
access as a last resort.

>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30113
> ---
>  gdb/nat/linux-namespaces.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/gdb/nat/linux-namespaces.c b/gdb/nat/linux-namespaces.c
> index 4b1fee18425..8922717be10 100644
> --- a/gdb/nat/linux-namespaces.c
> +++ b/gdb/nat/linux-namespaces.c
> @@ -935,6 +935,13 @@ linux_mntns_access_fs (pid_t pid)
>  	  if (error == ENOSYS)
>  	    error = ENOTSUP;
>  
> +	  /* EPERM indicates the required capabilites are not available
> +	     for this. Fall back to the old direct gdb behaviour in
> +	     order to not break cases where this used to work as the
> +	     path could still be the same in both namespaces. */

The reference to "old direct gdb behaviour" here should be removed.
It's OK to have comments like "This code exists for backwards
compatibility with old GDB behaviour...", but that isn't the case here.

The comment should justify the new code in terms of the desired
behaviour of GDB, so something like:

  /* EPERM indicates the required capabilites to setns() are not
     available.  It is possible that the file is directly visible to
     GDB, so, rather than just failing at this point, lets at least try
     direct access.  */
  if (error == EPERM)
    {
      warning (_("blah blah something about trying direct access"));
      return MNSH_FS_DIRECT;
    }

Though I would recommend trying 'set sysroot' and seeing if that solves
the access problems you are seeing.

Thanks,
Andrew

> +	  if (error == EPERM)
> +	    return MNSH_FS_DIRECT;
> +
>  	  errno = error;
>  	  return MNSH_FS_ERROR;
>  	}
> -- 
> 2.40.1


      reply	other threads:[~2023-09-20  8:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-19 23:51 Tyson Whitehead
2023-09-20  8:48 ` Andrew Burgess [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zg1hxmav.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=twhitehead@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).