Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1968490pxu; Sun, 13 Dec 2020 09:09:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzb765bwMxXHtbJSe6REo3FDR6p8Re4Rupw1dLjUiiYTWolHD0CRvUAxnVnc/+loZmnI5RV X-Received: by 2002:a50:bc15:: with SMTP id j21mr5586857edh.187.1607879350845; Sun, 13 Dec 2020 09:09:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607879350; cv=none; d=google.com; s=arc-20160816; b=FRp01GWL8zFgsi4j5pEt3KPp2rXfcI0hbCpKVB1rU7BPwOGKdw2NXZ8gQRskJ+TNEe 573Wd+PmIV3UKBsTAWjzmRw8W8ebpqtWjExxLW63iIlZgZnXJJQT3/zpcVY6TOsoxWSl uylat9sqv5CrgrghRE+fVY5xap4gEQYy9xaYqoh/UdahOgPG467nPW9XddXMDerkNbvM IwIkuWjnyLgVQKkbRA3/CdlIkYn1+LeKiGzvQmedCmHjICGDtnq88CboBDyN3GnAZcv7 2AqCAPzAFmmSJL9J6C9hodCMi8k4V9N3U1RRDISjQbGdCoKQHZYOcNqE7sCKzIG+zOWK jnWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WvFf+jA75Sbv8N99WjSMJITzF6r6kvLC4AxYbTkoaMU=; b=iTEG5F+d/iDj6Sv9a2YybeSmwB3Hypku6iG/VirO22WekYoX+RG6EUYZSHsZ1MvTks XKXOJBmA2epzI2XiKgfEfeLjiNqOlMZqdMWWuGazI9S1NkZNxt4Ie59zefzLIcjw5Kl1 b5sgWEguiCgSxqhPjtIeOQNjJwi+ruKq2MkEQAzHiyElTBUGiG38qdRMgNe+TMGxh8Yp +k3N0TdbdZlcor2M+BMAcmNey8yQZjRtfjwvI9WQSewxHHbFR3yLmsEUGP1ADpcYHqDn syx84tKZZdJ0lH+bcjlymbYdhD/6hQxQAeDVmC9FHQJKr2MMfCjBTcAQ5RoOXbBPZjjl JEZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=pzSQ419n; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o60si8999631eda.61.2020.12.13.09.08.48; Sun, 13 Dec 2020 09:09:10 -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; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=pzSQ419n; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407918AbgLLU4V (ORCPT + 99 others); Sat, 12 Dec 2020 15:56:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407890AbgLLU4U (ORCPT ); Sat, 12 Dec 2020 15:56:20 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A606BC0613CF; Sat, 12 Dec 2020 12:55:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=WvFf+jA75Sbv8N99WjSMJITzF6r6kvLC4AxYbTkoaMU=; b=pzSQ419n0/LzeB7FPfxuvjdg1b S+KMbAXTdTnw6SDA8CSdpfxIgeWbEoFXmLZIY5Q4KhhjNwHFcpz8n6hjPG4GTmAH5wdkzfngtMaVq doC3EYKNRYIzoBcoWdq/g71S7JEjPAFCgyPMWBJJYOGJRzMAXbnSlbLMq1kEkCMOeo0ssnaZHSWZg 8jruB4/ILM61wOfh2AXUsUZVQbAVUZmhJcF7AhI2AfKp030/D3yPmxW4z6Ac+HEGGXB3j8bTfq8UX Cdx/JUpCZTWPTMRDRidUP3OzTz4MgZ0+cH2yW0r43+wa/77saKX3wXQJCiugCWjC7jwRRkC3srPWz MARMV+pg==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1koBvG-0005AR-R6; Sat, 12 Dec 2020 20:55:22 +0000 Date: Sat, 12 Dec 2020 20:55:22 +0000 From: Matthew Wilcox To: Stephen Brennan Cc: 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 , Eric Biederman , Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] proc: Allow pid_revalidate() during LOOKUP_RCU Message-ID: <20201212205522.GF2443@casper.infradead.org> References: <20201204000212.773032-1-stephen.s.brennan@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201204000212.773032-1-stephen.s.brennan@oracle.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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);