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.133.124]) by passt.top (Postfix) with ESMTP id 93EAE5A004C for ; Wed, 05 Jun 2024 18:24:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717604692; 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: in-reply-to:in-reply-to:references:references; bh=6Nqmr7/N5PvzHfD/6pi4RHq98mVxcICc+qKMdkEn694=; b=AnGJWYXD6YSGAkRqBtSyyZZrUXti35gNS4VGClRFr80vG11LJoUvUjGuOhNf//N6d+3HMG M/68GjVIBYzEIO5j/IOq3tfhgSUKw6nwtUfG7KYjckKepDb5j92RG9tgxsLqyDEfG1MK8R //fesVbtByefCf7T5fDnjS6zjLq+yXQ= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-46-c7f_qrsfORK0WZW4OMxmSQ-1; Wed, 05 Jun 2024 12:24:50 -0400 X-MC-Unique: c7f_qrsfORK0WZW4OMxmSQ-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-44026115fa1so20028751cf.3 for ; Wed, 05 Jun 2024 09:24:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717604690; x=1718209490; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=6Nqmr7/N5PvzHfD/6pi4RHq98mVxcICc+qKMdkEn694=; b=X3QOGfCdjK8Rq6C2P29u/oZnMDPsHx4hJ6j3E73QAjoYndJzmvdr72QeHbeL8YZ1Qq 5hkxD1tWa6oaJWhzewqWbDTxURVWgUWLYg5cM6VxbgYnKajguQIXqagwtGFEffBKslmm SvtVLQUMJ1G0G7gE8lmy9EYuP5m6+jzKMkaJUy+yvFDkiJ02tS4dV9NiXCXLnn48uDTm Uc0c7o85eb0NvBpXBBarjHvWGOloUv+7Ocwbr05N5Wf2B6WP8H0bGgRbqeu36y7clXFk qZI4zmM/FAK+KXodQ3C9iwWZJSdGFiA2/fO9B0yJO85XxiFTncGcJX73MA6kLUv7lNIb hm+Q== X-Forwarded-Encrypted: i=1; AJvYcCV+qcrRfWHrh0saP+CBune9WDGp+UXXGAmt35PIeA5HaqRFRAudDVAGq3E8S2AupBnITl/36HXtkCS7N8mVjvhbd2bP X-Gm-Message-State: AOJu0YydepjhVvq0yiOuOqazi7Kx2eSLaYjjMWvXOtfbj6jmKbBnfCGi C53ENKSKA7m3/ddyyla02sqTt95rdVG3V+EU0YlKMn9gnM8nj5Kvg0Ltu8gm/GFlNodnAOl/X4Y yKWBSW+cMGTwx9771EJtTMIVryaHLvC3BL9g3/e15auKUPflCJQ== X-Received: by 2002:ac8:574e:0:b0:43a:2a23:4341 with SMTP id d75a77b69052e-4402b67ad75mr32363681cf.63.1717604690042; Wed, 05 Jun 2024 09:24:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZ/4dl8uqh8WLyg4ONN0i2hfqGyeMxk9dzWswWp2dg0Pv2Ay9a99Rmg/LmzaGv9UaH1A3YFg== X-Received: by 2002:ac8:574e:0:b0:43a:2a23:4341 with SMTP id d75a77b69052e-4402b67ad75mr32363221cf.63.1717604689252; Wed, 05 Jun 2024 09:24:49 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794f2efc82csm455122785a.21.2024.06.05.09.24.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jun 2024 09:24:48 -0700 (PDT) Date: Wed, 5 Jun 2024 18:23:52 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH] selinux: Allow access to user_devpts Message-ID: <20240605182352.5341003f@elisabeth> In-Reply-To: References: <20240528101256.37a74bc8@elisabeth> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 7IGVE6GJJLXI4LQSPQ2W7HJXZZNJDGUP X-Message-ID-Hash: 7IGVE6GJJLXI4LQSPQ2W7HJXZZNJDGUP X-MailFrom: sbrivio@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: Derek Schrock , passt-dev@passt.top 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: On Tue, 28 May 2024 19:25:15 +1000 David Gibson wrote: > On Tue, May 28, 2024 at 10:12:56AM +0200, Stefano Brivio wrote: > > On Tue, 28 May 2024 16:55:55 +1000 > > David Gibson wrote: > > > > > On Sun, May 26, 2024 at 06:28:42PM -0400, Derek Schrock wrote: > > > > Allow access to user_devpts. > > > > > > > > $ pasta --version > > > > pasta 0^20240510.g7288448-1.fc40.x86_64 > > > > ... > > > > $ awk '' < /dev/null > > > > $ pasta --version > > > > $ > > > > > > > > While this might be a awk bug it appears pasta should still have access > > > > to devpts. > > > > Derek, thanks for the patch! > > > > > It's not clear to me why pasta would need any access to /dev/pts. The > > > shell that pasta spawns does, of course, but it should already live in > > > a difference security context. > > > > Note that that doesn't happen in a shell pasta spawned: pasta --version > > doesn't do that. > > Oh, good point. I missed what was going on in that example. > > > It's just that after that awk comamnd, enabling access to > > user_tty_device_t doesn't seem to be enough anymore, we need > > user_devpts_t then. Which is probably something reasonable to enable > > anyway. > > Hmmm.. this still doesn't make sense to me. AFAIK, /dev/pts is about > managing pseudo-ttys, I see no reason we'd need to do that. Our > stdout *could* be a pseudo-tty, I suppose. But surely selinux can't > be requiring us to explicitly allow for any possible stdout/stderr > target? Especially not one as completely routine as a pseudo-tty - > that will be the case for anything run in an xterm. In general, one should use the userdom_use_user_terminals interface provided by system/userdomain.if (this is Fedora's core policy, https://github.com/fedora-selinux/selinux-policy.git): interface(`userdom_use_user_terminals',` gen_require(` type user_tty_device_t, user_devpts_t; ') allow $1 user_tty_device_t:chr_file rw_term_perms; allow $1 user_devpts_t:chr_file rw_term_perms; ') but I would like to avoid using it because we don't really need to "use" terminals: pasta doesn't need to ioctl() or open() any, and rw_term_perms is defined as follows: define(`rw_inherited_term_perms', `{ getattr lock read write append ioctl }') define(`rw_term_perms', `{ rw_inherited_term_perms open }') That's why I went with the current: allow pasta_t user_tty_device_t:chr_file { append read write }; instead, and if you look at e.g. userdom_base_user_template template, also in system/userdomain.if: allow $1_usertype user_devpts_t:chr_file { setattr rw_chr_file_perms }; term_create_pty($1_usertype, user_devpts_t) # avoid annoying messages on terminal hangup on role change dontaudit $1_usertype user_devpts_t:chr_file ioctl; allow $1_usertype user_tty_device_t:chr_file { setattr rw_chr_file_perms }; # avoid annoying messages on terminal hangup on role change dontaudit $1_usertype user_tty_device_t:chr_file ioctl; rules seem to be generally repeated for user_devpts_t and user_tty_device_t, that is, there seems to be no type subsuming both. > I also can't fathom why running awk would change anything. Could > there be something bogus in the selinux profile of the original shell > which allows the awk invocation to change the context somehow? I can reproduce this on Fedora 40 and Fedora Rawhide, and it also happens after running 'awk --version' with no redirection whatsoever. But not, say, after 'ls', or 'ls --version'. I can't see any domain change, either: $ ps -eZ -q $$ LABEL PID TTY TIME CMD unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 96009 pts/0 00:00:00 bash $ awk --version | wc -l 15 $ ps -eZ -q $$ LABEL PID TTY TIME CMD unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 96009 pts/0 00:00:00 bash $ pasta --version $ There's no difference between labels of ls and awk: $ ls -lZ /usr/bin/awk /usr/bin/gawk /usr/bin/ls lrwxrwxrwx. 1 root root system_u:object_r:bin_t:s0 4 Jan 24 00:00 /usr/bin/awk -> gawk -rwxr-xr-x. 1 root root system_u:object_r:bin_t:s0 764024 Jan 24 00:00 /usr/bin/gawk -rwxr-xr-x. 1 root root system_u:object_r:bin_t:s0 145480 Apr 2 00:00 /usr/bin/ls and I don't see anything different being done on stdout: $ strace -e ioctl awk --version ioctl(1, TCGETS, {c_iflag=ICRNL|IXON|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0 GNU Awk 5.3.0, API 4.0, PMA Avon 8-g1, (GNU MPFR 4.2.1, GNU MP 6.3.0) [...] $ strace -e ioctl ls ioctl(1, TCGETS, {c_iflag=ICRNL|IXON|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0 ioctl(1, TIOCGWINSZ, {ws_row=56, ws_col=191, ws_xpixel=0, ws_ypixel=0}) = 0 [...] so, while this looks weird and it would be interesting to understand what's so special with awk, the issue fixed by this patch is anyway a quite annoying one, not strictly related to whatever is happening with awk, and for the moment I would be inclined to apply the patch as it is, unless somebody sees any harm in that. -- Stefano