From patchwork Tue Sep 19 23:51:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyson Whitehead X-Patchwork-Id: 76415 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D08623858296 for ; Tue, 19 Sep 2023 23:52:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D08623858296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695167537; bh=pLGBxZjc0GnwanlbjRAhx5ZbR2BMPsTNvXbjOXJXJT0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Pd5WOjAyKBJ6GqTp39inPe0Ef8mGvqKOoJOPSjjcuQAYSB4NVdBjXhrFQlMGSR8hM D9C/vJ/NY9/3D34MJb3DkWkRPeBtDXUSS4QfPWQVkU08SzCdtAIIiDmm26HDsMpg3w 4BUmBxRNbzqJ054bJ0TwqvlLMyi5W9AvlxgcHICM= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by sourceware.org (Postfix) with ESMTPS id 439913858D20 for ; Tue, 19 Sep 2023 23:51:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 439913858D20 Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-76dc77fd024so400824185a.3 for ; Tue, 19 Sep 2023 16:51:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695167512; x=1695772312; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pLGBxZjc0GnwanlbjRAhx5ZbR2BMPsTNvXbjOXJXJT0=; b=mR8W6E+qkfJHKaKXR1MyLW73RXMxI1cg+PdMEzXl2WPNJr8vpCeX3NIhyCHp1bEX/L dAR4EpPe4UXsWT4qkXVRshwOyn1HytzFkBAhvzE5C4ho5ygTg306Z37IbMD0AogHU/uC gnBr/tKCDMCQKCEW8CUJ4qPkYWMJvkGGNmOEjbA2gxxSUJphDk+cBVxulMCMKRqudhMk pF9Oqn42Jeyi2DmJOQs3mK3zEDwHvTkRmoW842QrT12+BS78i1Vy4JEwEFxHLGge1Zbv b9RaFD9skIk4K95PfWx3QVLIB2yQejlgkf6OsdlZW98iqym+Lo+pK999qgYfG+uW68XG h1vQ== X-Gm-Message-State: AOJu0Yw08bzDvbBiFIjOKOTYkeLwG8qbXy3K0lZbFN3+9eKov/LIA0hu ZpdShjLP86YHOBpBOrzWDCxrCXB5qeM= X-Google-Smtp-Source: AGHT+IHOoHCtDPnLgqJEzg6Yi9TtyA6E9xIGNcWwlHlyEong0kruh3OaSUWNRyUAResoWGxiTfGi9w== X-Received: by 2002:a05:620a:3954:b0:770:f3e6:ba0b with SMTP id qs20-20020a05620a395400b00770f3e6ba0bmr1172726qkn.14.1695167512217; Tue, 19 Sep 2023 16:51:52 -0700 (PDT) Received: from tux.cdnet (ip-24-54-87-164.user.start.ca. [24.54.87.164]) by smtp.gmail.com with ESMTPSA id t4-20020a05620a004400b007682af2c8aasm4390835qkt.126.2023.09.19.16.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 16:51:51 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Tyson Whitehead Subject: [PATCH] Fallback to direct access if lacking pemission for linux namespaces Date: Tue, 19 Sep 2023 19:51:34 -0400 Message-Id: <20230919235134.2243437-1-twhitehead@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , X-Patchwork-Original-From: Tyson Whitehead via Gdb-patches From: Tyson Whitehead Reply-To: Tyson Whitehead Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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. 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. 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. */ + if (error == EPERM) + return MNSH_FS_DIRECT; + errno = error; return MNSH_FS_ERROR; }