Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp37762rdb; Wed, 29 Nov 2023 19:07:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmi+v1MdwOBZGTXGCYbZww8H07PFaYO3PEgYpaHwLGJwwq18+PledS9vVEArGwlzvrSHY3 X-Received: by 2002:a92:dd12:0:b0:35d:3e2e:b631 with SMTP id n18-20020a92dd12000000b0035d3e2eb631mr383019ilm.14.1701313674250; Wed, 29 Nov 2023 19:07:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701313674; cv=none; d=google.com; s=arc-20160816; b=qHkms9yJkz6t16oZvoJpvIrxMTHiANodR/s986T3zcZEJ7CvgYXg2lDnZsMATVbbQJ 2fAQ0kWK9RPjWg8dEnjIAS359pYEzw7VWVWl4jKnpjfvAtW66DsEdaVXz7EqeGTZvvbv qqKIPWl1e9wOOQJ3rPBq1WgFmPdGXdnYJcDtvKoaayna+/j9LFdA5ZflNmPZIBgRn57J mrKknGjMOBjfKKUMb8OSkhG5uSzbavL6kJM8ddJwhuif25HHiaBIKwSPN4ttPH5fLCK9 aez5qS6RmwmKi5Qc8X57yUhWIsBcuoWWnr6AKTURQD5BQQV8/lxK8TYQJM5hQ4Jj6jIK dtJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=F6MENshfkaH8bmU45se60CAkvuaOjjKOiHZKlEZ6xHA=; fh=Ushd2AYlhGPigPQ0Tz0l6apQOB9q8Fj6937eG5TOIGk=; b=kAiMqgkgyo468U4M6cDAMDe6tQd98vsIU8KJ3iThHmxL3HW+S0ISiARFNYCcw8G96A Gvrt4ykaqDb6mCv77J5cH0/EM3om1SO+UokX0exv3T+B5bbIhKfa5JGNw05aSczOd+RD ya9jH63KMBambtaYZ9s8XkmQKFB4iGZu6g0272AcU0A9kqIumUh5EBwsICDKX2eiSoyn fuB8SNWnzgPM9l2cYUhXpRiwSBQsS0tyDSQvrvO4cCmzPV8oYp4n/r9RE4aJiImO3DHo wczYa1FE30i+OMJWAUgoyOUdIgvQ9RT0fqgL2QhZ/U5dJg98BMdj8BGOg8uSfvUVzUmk qARA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=TiebifzN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id q17-20020a656851000000b005ab3f1980f3si327188pgt.68.2023.11.29.19.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 19:07:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=TiebifzN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 6CEA7803A651; Wed, 29 Nov 2023 19:07:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344173AbjK3DHe (ORCPT + 99 others); Wed, 29 Nov 2023 22:07:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230393AbjK3DHc (ORCPT ); Wed, 29 Nov 2023 22:07:32 -0500 Received: from smtp-fw-9105.amazon.com (smtp-fw-9105.amazon.com [207.171.188.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 181DA1A6; Wed, 29 Nov 2023 19:07:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1701313659; x=1732849659; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F6MENshfkaH8bmU45se60CAkvuaOjjKOiHZKlEZ6xHA=; b=TiebifzNmzCNm81Um+msamPug8i5DyN9+i+W/0Dn7BMgrFu9imAX4XpY BE+KmhVSBn8KZ+qMLA8dhW2zf9EJNGlgM3Ll/D4KF/jOK9a6ly/o9GVvZ UNuGkly2tqMTx6/dMNpPAeF4SFyvXUgfcO9WpyuOofDvj4TIfqXH8ZNkf 0=; X-IronPort-AV: E=Sophos;i="6.04,237,1695686400"; d="scan'208";a="687984968" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1e-m6i4x-245b69b1.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-9105.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 03:07:38 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1e-m6i4x-245b69b1.us-east-1.amazon.com (Postfix) with ESMTPS id 1B2C6340019; Thu, 30 Nov 2023 03:07:35 +0000 (UTC) Received: from EX19MTAUWB001.ant.amazon.com [10.0.7.35:3462] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.36.6:2525] with esmtp (Farcaster) id 8beb2ad2-7780-40d5-9629-ec295a44c9fe; Thu, 30 Nov 2023 03:07:34 +0000 (UTC) X-Farcaster-Flow-ID: 8beb2ad2-7780-40d5-9629-ec295a44c9fe Received: from EX19D010UWA004.ant.amazon.com (10.13.138.204) by EX19MTAUWB001.ant.amazon.com (10.250.64.248) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Thu, 30 Nov 2023 03:07:34 +0000 Received: from u0acfa43c8cad58.ant.amazon.com (10.106.101.41) by EX19D010UWA004.ant.amazon.com (10.13.138.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Thu, 30 Nov 2023 03:07:34 +0000 From: Munehisa Kamata To: CC: , , , , Subject: Re: [PATCH] proc: Update inode upon changing task security attribute Date: Wed, 29 Nov 2023 19:07:21 -0800 Message-ID: <20231130030721.780557-1-kamatam@amazon.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <6f02ce82-3697-4e76-aae6-13440e1bfbad@schaufler-ca.com> References: <6f02ce82-3697-4e76-aae6-13440e1bfbad@schaufler-ca.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.106.101.41] X-ClientProxiedBy: EX19D038UWC004.ant.amazon.com (10.13.139.229) To EX19D010UWA004.ant.amazon.com (10.13.138.204) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 29 Nov 2023 19:07:51 -0800 (PST) Hi Casey, On Wed, 2023-11-29 18:28:55 -0800, Casey Schaufler wrote: > > On 11/29/2023 4:37 PM, Munehisa Kamata wrote: > > I'm not clear whether VFS is a better (or worse) place[1] to fix the > > problem described below and would like to hear opinion. > > Please To: or at least Cc: me on all Smack related issues. Will do that next. > > > > If the /proc/[pid] directory is bind-mounted on a system with Smack > > enabled, and if the task updates its current security attribute, the task > > may lose access to files in its own /proc/[pid] through the mountpoint. > > > > $ sudo capsh --drop=cap_mac_override -- > > # mkdir -p dir > > # mount --bind /proc/$$ dir > > # echo AAA > /proc/$$/task/current # assuming built-in echo > > I don't see "current" in /proc/$$/task. Did you mean /proc/$$/attr? Ahh, yes, I meant /proc/$$/attr/current. Sorry about that... > > # cat /proc/$$/task/current # revalidate > > AAA > > # echo BBB > dir/attr/current > > # cat dir/attr/current > > cat: dir/attr/current: Permission denied > > # ls dir/ > > ls: cannot access dir/: Permission denied > > # cat /proc/$$/attr/current # revalidate > > BBB > > # cat dir/attr/current > > BBB > > # echo CCC > /proc/$$/attr/current > > # cat dir/attr/current > > cat: dir/attr/current: Permission denied > > > > This happens because path lookup doesn't revalidate the dentry of the > > /proc/[pid] when traversing the filesystem boundary, so the inode security > > blob of the /proc/[pid] doesn't get updated with the new task security > > attribute. Then, this may lead security modules to deny an access to the > > directory. Looking at the code[2] and the /proc/pid/attr/current entry in > > proc man page, seems like the same could happen with SELinux. Though, I > > didn't find relevant reports. > > > > The steps above are quite artificial. I actually encountered such an > > unexpected denial of access with an in-house application sandbox > > framework; each app has its own dedicated filesystem tree where the > > process's /proc/[pid] is bind-mounted to and the app enters into via > > chroot. > > > > With this patch, writing to /proc/[pid]/attr/current (and its per-security > > module variant) updates the inode security blob of /proc/[pid] or > > /proc/[pid]/task/[tid] (when pid != tid) with the new attribute. > > > > [1] https://lkml.kernel.org/linux-fsdevel/4A2D15AF.8090000@sun.com/ > > [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/security/selinux/hooks.c#n4220 > > > > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") > > Signed-off-by: Munehisa Kamata > > --- > > fs/proc/base.c | 23 ++++++++++++++++++++--- > > 1 file changed, 20 insertions(+), 3 deletions(-) > > > > diff --git a/fs/proc/base.c b/fs/proc/base.c > > index dd31e3b6bf77..bdb7bea53475 100644 > > --- a/fs/proc/base.c > > +++ b/fs/proc/base.c > > @@ -2741,6 +2741,7 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, > > { > > struct inode * inode = file_inode(file); > > struct task_struct *task; > > + const char *name = file->f_path.dentry->d_name.name; > > void *page; > > int rv; > > > > @@ -2784,10 +2785,26 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, > > if (rv < 0) > > goto out_free; > > > > - rv = security_setprocattr(PROC_I(inode)->op.lsm, > > - file->f_path.dentry->d_name.name, page, > > - count); > > + rv = security_setprocattr(PROC_I(inode)->op.lsm, name, page, count); > > mutex_unlock(¤t->signal->cred_guard_mutex); > > + > > + /* > > + * Update the inode security blob in advance if the task's security > > + * attribute was updated > > + */ > > + if (rv > 0 && !strcmp(name, "current")) { > > + struct pid *pid; > > + struct proc_inode *cur, *ei; > > + > > + rcu_read_lock(); > > + pid = get_task_pid(current, PIDTYPE_PID); > > + hlist_for_each_entry(cur, &pid->inodes, sibling_inodes) > > + ei = cur; > > + put_pid(pid); > > + pid_update_inode(current, &ei->vfs_inode); > > + rcu_read_unlock(); > > + } > > + > > out_free: > > kfree(page); > > out: >