Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp14351181pxu; Mon, 4 Jan 2021 22:02:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1nK0Enm5T8BjmabVKSdVTFNwHJcZL9VA0bqEAPgWxTc/08DSQVLiftPjaQ4A8C/ULfOFV X-Received: by 2002:a50:8387:: with SMTP id 7mr71419907edi.131.1609826553482; Mon, 04 Jan 2021 22:02:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609826553; cv=none; d=google.com; s=arc-20160816; b=w3wiC/OxIeHASnqtx1r7huaEZrhFW0rKNt9ePREoJgQ0TBtAeWASkvCJkIF28lAbxr 2PNAW287UQA4puaWaB13gNn3Qf51wGQ/U89t9seIuDkmva3TKw77puiNebo6yTsrpkGh OpVi2qz7yLZ3AehojeHqM8hEQuO6tGSp/VuZaQlmi3DKFtQEC+fd1JaXIzPAJOg4TOa2 0TRo7ZJDQE3FqFo9+S32A2CJa7NAvS52JbuGq3N+TqTwkE5a1OheLwkK28e057OVsW6d yaTSSFQJNV5L2E3Nai2yuT0N56XvB4sC+OyRdsIkCLafRJ+TGXudZq8/i9pDMBUn8EL5 dVLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=4XWfe91yMoXcPIyqysHzGUhYux0zQD4aI5kV4Xw5/t0=; b=P56j53F6nXcztM8UTcUH4690/rcttVpXafeJNIKXHQvx+6tCMEHXVhRSnlh5ZY2o0t EhFJcDdsZNh7AQriftZ2VKZoNjz/Z5KIK2eAmnaqMc1SD8D+AgnfC9QREZ5gArLOcFQv VBK6GzETX01VtDFY3hhPawUejYIobeulYaGkESL3cUBGdKo3WnxYfvKdOmJ5c0SYo910 cmf2GFyxXmSJI/3kbxDXFRKu/8buM2KcrcKw0XP4SDMmgZPo7B7aBvW4r+rYYbULLvID w5T2R5fkGV3a/bgBNlHSr3em7ubtzOdvTpp70FPhwpDwj6nXO73sEbb3hO55Lkf9YbhO M9Hg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i4si29055254ejg.258.2021.01.04.22.02.10; Mon, 04 Jan 2021 22:02:33 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726391AbhAEGAn (ORCPT + 99 others); Tue, 5 Jan 2021 01:00:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725919AbhAEGAn (ORCPT ); Tue, 5 Jan 2021 01:00:43 -0500 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B17B0C061793; Mon, 4 Jan 2021 22:00:02 -0800 (PST) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kwfNY-006yqt-0a; Tue, 05 Jan 2021 05:59:36 +0000 Date: Tue, 5 Jan 2021 05:59:35 +0000 From: Al Viro 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 , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Matthew Wilcox Subject: Re: [PATCH v4] proc: Allow pid_revalidate() during LOOKUP_RCU Message-ID: <20210105055935.GT3579531@ZenIV.linux.org.uk> References: <20210104232123.31378-1-stephen.s.brennan@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210104232123.31378-1-stephen.s.brennan@oracle.com> Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 04, 2021 at 03:21:22PM -0800, Stephen Brennan wrote: > The pid_revalidate() function drops from RCU into REF lookup mode. When > many threads are resolving paths within /proc in parallel, this can > result in heavy spinlock contention on d_lockref as each thread tries to > grab a reference to the /proc dentry (and drop it shortly thereafter). > > Investigation indicates that it is not necessary to drop RCU in > pid_revalidate(), as no RCU data is modified and the function never > sleeps. So, remove the LOOKUP_RCU check. Umm... I'm rather worried about the side effect you are removing here - you are suddenly exposing a bunch of methods in there to RCU mode. E.g. is proc_pid_permission() safe with MAY_NOT_BLOCK in the mask? generic_permission() call in there is fine, but has_pid_permission() doesn't even see the mask. Is that thing safe in RCU mode? AFAICS, this static int selinux_ptrace_access_check(struct task_struct *child, unsigned int mode) { u32 sid = current_sid(); u32 csid = task_sid(child); if (mode & PTRACE_MODE_READ) return avc_has_perm(&selinux_state, sid, csid, SECCLASS_FILE, FILE__READ, NULL); return avc_has_perm(&selinux_state, sid, csid, SECCLASS_PROCESS, PROCESS__PTRACE, NULL); } is reachable and IIRC avc_has_perm() should *NOT* be called in RCU mode. If nothing else, audit handling needs care... And LSM-related stuff is only a part of possible issues here. It does need a careful code audit - you are taking a bunch of methods into the conditions they'd never been tested in. ->permission(), ->get_link(), ->d_revalidate(), ->d_hash() and ->d_compare() instances for objects that subtree. The last two are not there in case of anything in /proc/, but the first 3 very much are.