Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2022054pxu; Sun, 13 Dec 2020 10:52:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjrucSiDXnRuukq3Eq9/A5RfevnTnnoFt68QEQeCUByw731T6483j5llAFz/vFvNqluJed X-Received: by 2002:a50:f40e:: with SMTP id r14mr21096923edm.5.1607885522320; Sun, 13 Dec 2020 10:52:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607885522; cv=none; d=google.com; s=arc-20160816; b=xfpMSJ60NIGbN2pqxGAnmDKmFWiHi4g1oOESF65E8/Sx/YhX2U3z0gOgBSCviCrt6e 1O0xUkz1dOBWI4uj9IQQUZDe7tdwvIz0ynfqYfMFZ6heBGBI6FLy6ND00oe3Kca3fGtT bIDiEFyb4tXabRmkgE4ccCQqxQFVCH9YO1nJTe6vPVO3WApFSgOTMBDmI966Cxs0d0kq WWb08hI8S51ULg1RednUPkXqdfQiLEkUGEIMpwfPhfVXp9xd3cOTUmBF87H3ekBVtRKy 10tEOQsaQbZouBTSvY6B7ZTGnvaWg5ACl0Yl/OGDawDu5fCFCQNRJ+xIHMkg5vvrBvs5 FLkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:mime-version:user-agent:message-id :in-reply-to:date:references:cc:to:from; bh=/NWIIcPs3h5rz2W5v11/utbHFyw0Wo6T5XmxqqpHtbk=; b=S2Ab2UYYh2rP7+mvEdn4+ocMAufghqFMrOww788L0cIgsDFnCFXvK/+ooI8K7k64ar 4ryR8RRB7/rQJk+yxkm0T3aYLGUhxHFJ0JIbMDRpkJoAFdcF9XKQiQwEe7/mffRP0T7o bjy/0PJH594oZZDH5ghDbUowBVJ3QFQAOQKMN6Hz/gcL1Ck+xw0YZhKyv1m9o8OSlLu6 /nY+PqoGMV2jH/Y/cKuhKvPDOytgs012/Ou4qtRm8FE33zwX6gscl9ydnjJe1aWQfOY4 XClLZRQAaPn3ZJywAIpNqcaIpMQgpFuAN8P9N3pzfTcaKAgusP3NEIxOqN6OLlaxRNZR bmNw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t20si9029621edw.31.2020.12.13.10.51.40; Sun, 13 Dec 2020 10:52:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727708AbgLMOYZ (ORCPT + 99 others); Sun, 13 Dec 2020 09:24:25 -0500 Received: from out02.mta.xmission.com ([166.70.13.232]:45992 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725778AbgLMOYG (ORCPT ); Sun, 13 Dec 2020 09:24:06 -0500 Received: from in01.mta.xmission.com ([166.70.13.51]) by out02.mta.xmission.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1koSHQ-0088st-9C; Sun, 13 Dec 2020 07:23:20 -0700 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1koSHL-00089n-7m; Sun, 13 Dec 2020 07:23:20 -0700 From: ebiederm@xmission.com (Eric W. Biederman) To: Matthew Wilcox Cc: Stephen Brennan , Alexey Dobriyan , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, Paul Moore , Stephen Smalley , Eric Paris , selinux@vger.kernel.org, Casey Schaufler , Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org References: <20201204000212.773032-1-stephen.s.brennan@oracle.com> <20201212205522.GF2443@casper.infradead.org> Date: Sun, 13 Dec 2020 08:22:32 -0600 In-Reply-To: <20201212205522.GF2443@casper.infradead.org> (Matthew Wilcox's message of "Sat, 12 Dec 2020 20:55:22 +0000") Message-ID: <877dpln5uf.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1koSHL-00089n-7m;;;mid=<877dpln5uf.fsf@x220.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18GcGxMolQ2R37qJNnK7xeJF6oKU8YDCBs= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on sa07.xmission.com X-Spam-Level: X-Spam-Status: No, score=0.5 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG,T_TooManySym_01, T_TooManySym_02,XMSubLong autolearn=disabled version=3.4.2 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 0.7 XMSubLong Long Subject * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_02 5+ unique symbols in subject X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Matthew Wilcox X-Spam-Relay-Country: X-Spam-Timing: total 4670 ms - load_scoreonly_sql: 0.06 (0.0%), signal_user_changed: 9 (0.2%), b_tie_ro: 8 (0.2%), parse: 0.94 (0.0%), extract_message_metadata: 12 (0.3%), get_uri_detail_list: 1.49 (0.0%), tests_pri_-1000: 5 (0.1%), tests_pri_-950: 1.25 (0.0%), tests_pri_-900: 1.03 (0.0%), tests_pri_-90: 235 (5.0%), check_bayes: 233 (5.0%), b_tokenize: 8 (0.2%), b_tok_get_all: 8 (0.2%), b_comp_prob: 2.5 (0.1%), b_tok_touch_all: 86 (1.8%), b_finish: 0.74 (0.0%), tests_pri_0: 252 (5.4%), check_dkim_signature: 0.60 (0.0%), check_dkim_adsp: 2.6 (0.1%), poll_dns_idle: 4138 (88.6%), tests_pri_10: 1.81 (0.0%), tests_pri_500: 4148 (88.8%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH v2] proc: Allow pid_revalidate() during LOOKUP_RCU X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Matthew Wilcox writes: > On Thu, Dec 03, 2020 at 04:02:12PM -0800, Stephen Brennan wrote: >> -void pid_update_inode(struct task_struct *task, struct inode *inode) >> +static int do_pid_update_inode(struct task_struct *task, struct inode *inode, >> + unsigned int flags) > > I'm really nitpicking here, but this function only _updates_ the inode > if flags says it should. So I was thinking something like this > (compile tested only). > > I'd really appreocate feedback from someone like Casey or Stephen on > what they need for their security modules. Just so we don't have security module questions confusing things can we please make this a 2 patch series? With the first patch removing security_task_to_inode? The justification for the removal is that all security_task_to_inode appears to care about is the file type bits in inode->i_mode. Something that never changes. Having this in a separate patch would make that logical change easier to verify. Eric > > diff --git a/fs/proc/base.c b/fs/proc/base.c > index b362523a9829..771f330bfce7 100644 > --- a/fs/proc/base.c > +++ b/fs/proc/base.c > @@ -1968,6 +1968,25 @@ void pid_update_inode(struct task_struct *task, struct inode *inode) > security_task_to_inode(task, inode); > } > > +/* See if we can avoid the above call. Assumes RCU lock held */ > +static bool inode_needs_pid_update(struct task_struct *task, > + const struct inode *inode) > +{ > + kuid_t uid; > + kgid_t gid; > + > + if (inode->i_mode & (S_ISUID | S_ISGID)) > + return true; > + task_dump_owner(task, inode->i_mode, &uid, &gid); > + if (!uid_eq(uid, inode->i_uid) || !gid_eq(gid, inode->i_gid)) > + return true; > + /* > + * XXX: Do we need to call the security system here to see if > + * there's a pending update? > + */ > + return false; > +} > + > /* > * Rewrite the inode's ownerships here because the owning task may have > * performed a setuid(), etc. > @@ -1978,8 +1997,15 @@ static int pid_revalidate(struct dentry *dentry, unsigned int flags) > struct inode *inode; > struct task_struct *task; > > - if (flags & LOOKUP_RCU) > + if (flags & LOOKUP_RCU) { > + inode = d_inode_rcu(dentry); > + task = pid_task(proc_pid(inode), PIDTYPE_PID); > + if (!task) > + return 0; > + if (!inode_needs_pid_update(task, inode)) > + return 1; > return -ECHILD; > + } > > inode = d_inode(dentry); > task = get_proc_task(inode);