Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp24334rdb; Wed, 29 Nov 2023 18:29:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IHFAeCbifHx5gNy7Yu9z2cfASOecTylyt/V4alF0NFlNXNN30thw5RDgox2Om0TnpAoECyr X-Received: by 2002:a05:6a20:8f10:b0:18d:961:564b with SMTP id b16-20020a056a208f1000b0018d0961564bmr4364374pzk.33.1701311363440; Wed, 29 Nov 2023 18:29:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701311363; cv=none; d=google.com; s=arc-20160816; b=fSp2zYFKPReqlwTB7NfuEo3+NJSK1WupnPR7TMQGYjoXi4HixKQBjNbufXbER1Wwp+ G3H7RheyEi4nT1qekZ1WIZgmYq4bTYsSmA8NDKGJBlaZeta7BmwkY6VmUI1G/gOZ/bn2 NDDfAUEyWRpVctodAx6vtanniTZSjiuh8KuitCZz6EGCmybAg6kjiqCouWp1t8JUTV4v uMrOWcgQAqIO0SK7m8ivn7sgA+nJyTzuLankcEXWeqCayMXl77EYIDwLQi6GovEkXlGy MEg7MLaP6L05wunVsaOIyevi6mJwnXvItfiZPdWY62etiCO/QG/YDJzdjJqEIZrFT7Bu AZgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=gL39ykAlNyN8xh3lAJOTUdf6ZI7rQ4ZW3xpbCJm57z8=; fh=9ONlau7B7D1PZXhAKKcNYVckd2mnVHGWukBKCnjoqaA=; b=vBSp1x+sFDbViV9QiCaGyXuwc4dGUwBr+yypiogM2mhmiEmFBOVQ2aJaKuwK4BCqss d7kL/s/OKW+/LiMMArEqnzHqumpL+fzEApDprMph5JdjHZJI+bjEWXxuwWbrIPrJVg4x s6z+slGH/TMx6E9mHrXSjh4xWrRxZktvs3/FoYZbYyrb9WwKuAy0GBOTPRx93c8Ovw2j h9b0T5A9uG+wxZuomBQU+fPU+H/gWmbCIYzsKuQ7F/KRmjfjZ8ooE7+OgrSJJrJoaVSj DYjZQL/NwQjGSGOcuVxIO8iIDmJh9vxx1bx7mb9PqnD5NiGFNE14MxoQY0FJcwuJh1q/ XhzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=e++ZB8cU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id c8-20020a170902aa4800b001cfd183c4f1si111364plr.547.2023.11.29.18.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 18:29:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=e++ZB8cU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 91E65802B05D; Wed, 29 Nov 2023 18:29:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344162AbjK3C27 (ORCPT + 99 others); Wed, 29 Nov 2023 21:28:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231536AbjK3C27 (ORCPT ); Wed, 29 Nov 2023 21:28:59 -0500 Received: from sonic316-27.consmr.mail.ne1.yahoo.com (sonic316-27.consmr.mail.ne1.yahoo.com [66.163.187.153]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D2F910D0 for ; Wed, 29 Nov 2023 18:29:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1701311343; bh=gL39ykAlNyN8xh3lAJOTUdf6ZI7rQ4ZW3xpbCJm57z8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=e++ZB8cU4B5RZlZWTWETzbfIBevyxqWN+0PnSQXZ4iR522FAU1IH1SWWh17ERaiUW2xx/Ssg4mICkGkYU578qCkNoWwZkpHiuCTPbCWWj0RrJ7YVyaIfIUjoHbLy+I+kCrOfTMJy2ZQK8zyNTmmTQeYhEKKfB289zmULWCxELnhSi+rkPnB+7gYmSbIfM7hpMSXLxP9R3EiQIXpS/0+F2Rcd1NoAIA5LMGm6SjQ/NlUyEtF7Y/tvmAAq/H/T0TF2qlDG0gb1Uckbh6oABzqeyaQYaLbhq37FzZhfHfJ4Unh3yrnhG0HDPvOGnkqj4enOUvagixGTh0zS1fzjKdA9Kg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1701311343; bh=JN4VtfytD/T9E5h1Ka6FxbjJ1okDdhGyGQa4AZq6vWT=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=ClFlSuFGReZ8IZyVNIM2eXSHBnFXuy03eUi81jkhIhHhgt0tZjg5sY3dNRbS9k38Q0BeHJAz22peMCvISijADp78v5zVgM8o8cXt85Y0908hfOq+9G4AU1vXf7/bu2awZDBzMrP8MkGT+DUb9CPprTO5TbnFkQ6MjfAbC9zhSErtBwxiW6eTjjWXRDMCw826KxJjIvXlSeFDzQ8nS7Lsx82M+GIsiC7K57GExNN1gYvWUX2CfxPGOxan8M9c1Uc0tLPeODlS1ueLXcjxtStHY5o4FYzU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SV7GoM1xOg7rkxotjyLpkp BwmJ2.3xdg0lF_3VdA12De8u3e_NLZxlVkwLkzQOJUdyY0k.LxHtmhkMkhao4VBdbyuHnfLpND4I YDrZZw0MeeWgdnUWRTjhxjslDZ25G5a1659q0TGXyudeaZ.lj9tQjPoQVMVWYth4R_4d7iSrW9xX F_rx7SAgb.fznygkLGjQTHZ6QMfx8YXyYn7dEzsIpOUxVqa_GkpHdHCsygjVaEIiPyy1c6Fxim0L Zk4xXYcDZdA-- X-Sonic-MF: X-Sonic-ID: 589800e8-cdf7-4ba8-aaee-54fb512f8a17 Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.ne1.yahoo.com with HTTP; Thu, 30 Nov 2023 02:29:03 +0000 Received: by hermes--production-gq1-5cf8f76c44-42dfr (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID d2206d053838777dcceb9a944e79273b; Thu, 30 Nov 2023 02:28:57 +0000 (UTC) Message-ID: <6f02ce82-3697-4e76-aae6-13440e1bfbad@schaufler-ca.com> Date: Wed, 29 Nov 2023 18:28:55 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] proc: Update inode upon changing task security attribute Content-Language: en-US To: Munehisa Kamata , linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, Casey Schaufler References: <20231130003704.31928-1-kamatam@amazon.com> From: Casey Schaufler In-Reply-To: <20231130003704.31928-1-kamatam@amazon.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.21896 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 29 Nov 2023 18:29:21 -0800 (PST) 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. > > 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? > # 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: