From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id A16425A026D for ; Fri, 23 Jun 2023 10:27:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687508829; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zSuNXkP7V8lmfYjR5qKabHlGCkG6JbK9LrjF/sx6Y4A=; b=GsUH22VIPJXoeHyUiH+0BIx1P0ZxYM5/6Y0MAbpsv5nAgK55/9LuftGVOOBBkVUz9M1FB9 pG6bO5k4NMy7TdeABASwqEYlHCL8PC/ajsFbYU11guoIIw/9Bv6JUbLYwxM4ALlK/DzGJS 2WvxHW90zJOHo4m/mvJRk3x05lDp5EM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-445-KN1vckcXNiObA4MMh-36Bg-1; Fri, 23 Jun 2023 04:27:07 -0400 X-MC-Unique: KN1vckcXNiObA4MMh-36Bg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 15AD31C04194 for ; Fri, 23 Jun 2023 08:27:07 +0000 (UTC) Received: from pholzing-fedora.redhat.com (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8625E15230A1; Fri, 23 Jun 2023 08:27:06 +0000 (UTC) From: Paul Holzinger To: passt-dev@passt.top Subject: [PATCH] isolation: keep CAP_SYS_PTRACE when required Date: Fri, 23 Jun 2023 10:25:32 +0200 Message-ID: <20230623082531.25947-2-pholzing@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: B57Z5SFUCDJVPAEB35AQTLNEJ47FM6X7 X-Message-ID-Hash: B57Z5SFUCDJVPAEB35AQTLNEJ47FM6X7 X-MailFrom: pholzing@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Paul Holzinger X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: When pasta is started from an existing userns and tries to join the netns from another process it fails to open /proc/$pid/ns/net due the missing CAP_SYS_PTRACE capability in the --netns-only case. A simple reproducer for this. First create a userns: $ unshare -r Then create a new netns inside it and try to join that netns with pasta. $ unshare -n sleep inf & $ pasta --config-net --netns /proc/$!/ns/net Signed-off-by: Paul Holzinger --- isolation.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/isolation.c b/isolation.c index 19932bf..1866724 100644 --- a/isolation.c +++ b/isolation.c @@ -202,9 +202,11 @@ void isolate_initial(void) * a mapping from UID 0, which only happens with pasta spawning a child * from a non-init user namespace (pasta can't run as root), we need to * retain CAP_SETFCAP too. + * We also need to keep CAP_SYS_PTRACE in order to join an existing netns + * path under /proc/$pid/ns/net which was created in the same userns. */ if (!ns_is_init() && !geteuid()) - keep |= BIT(CAP_SETFCAP); + keep |= BIT(CAP_SETFCAP) | BIT(CAP_SYS_PTRACE); drop_caps_ep_except(keep); } -- 2.41.0