Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp467596pxu; Tue, 5 Jan 2021 16:51:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJzKPOU/cyifboE4mLDpSgoo/CGaKMTLxjkyEvitoZySWLtwVHHmqQNYIvrj9+misWCeqDJ3 X-Received: by 2002:a17:906:b09a:: with SMTP id x26mr1337445ejy.199.1609894287921; Tue, 05 Jan 2021 16:51:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609894287; cv=none; d=google.com; s=arc-20160816; b=M2/srPZkZCDyBcM/6za+WBkcAnAm7sy1ZWe1IqBGdua3PpCaEvmhQqiSazJDJw2sVo E0SrjtrU5BbdHxnsprtTYixrFkHai4bzbEJxNaGInwRDcoLAkyJe4xtkqEpSEzkqMakK XneY2oDMwHlInp50w3xy+5LKwl72iZq2MVCqZMKYP3bnQLqFgpfMVQJaFjD9M/KZreNh riEr8+YlThzw+VDEPGc6GWC8ynfHCICByz+zpW2wEOyaPwfiuB3qkyLeLOAmsUcTAnzJ A9kITEHNcVIL94ULgLxPDCPt62uFBkPGoYf8tURMNbDl790bszZ1PK7NtAy9pyReqEWl QRPw== 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=L0Yr2ViHVy8k1iTnf1tRE2DJB7crXlyPtTPt/nEpgr4=; b=io3pE9CNsKBm8FSaLlWrsw69QjFGtQJYglhHWfPYF4YrGvEe26fTC6OlkUqkXJG3N5 VndDtJPdrXR0/JknV7onAxMDBR0ftDvMvaYx2eIzpyu71IE0nrAuRGTFR115wF+BHQWX AfVDpf28waI4dN7CSKWRJfHKt3v9SMkP2nsq/bU/qd08CHO3DbHWoT92GIskkpNiHvts pTPKuQYHGif2vApINa8vZD6DUbRl5SfYq5xreRZY8Nf1VqyobiZDM+b3aQLVJNkfVok2 /PtTbm3NBMBKiJODZS2t+smg5sA9B8KhUNN3Wukt+PLpjdEUbWMrZ9aGPq3BaAqp8W4d aJ2g== 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 go33si43071ejc.40.2021.01.05.16.51.04; Tue, 05 Jan 2021 16:51:27 -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 S1727207AbhAFAjC (ORCPT + 99 others); Tue, 5 Jan 2021 19:39:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727170AbhAFAjC (ORCPT ); Tue, 5 Jan 2021 19:39:02 -0500 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 840ECC061574; Tue, 5 Jan 2021 16:38:21 -0800 (PST) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kwwpv-007DLx-34; Wed, 06 Jan 2021 00:38:03 +0000 Date: Wed, 6 Jan 2021 00:38:03 +0000 From: Al Viro To: Paul Moore Cc: Stephen Brennan , Linus Torvalds , Alexey Dobriyan , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, 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: <20210106003803.GA3579531@ZenIV.linux.org.uk> References: <20210104232123.31378-1-stephen.s.brennan@oracle.com> <20210105055935.GT3579531@ZenIV.linux.org.uk> <20210105165005.GV3579531@ZenIV.linux.org.uk> <20210105195937.GX3579531@ZenIV.linux.org.uk> <87a6tnge5k.fsf@stepbren-lnx.us.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 05, 2021 at 07:00:59PM -0500, Paul Moore wrote: > > > Incidentally, LSM_AUDIT_DATA_DENTRY in mainline is *not* safe wrt > > > rename() - for long-named dentries it is possible to get preempted > > > in the middle of > > > audit_log_untrustedstring(ab, a->u.dentry->d_name.name); > > > and have the bugger renamed, with old name ending up freed. The > > > same goes for LSM_AUDIT_DATA_INODE... > > > > In the case of proc_pid_permission(), this preemption doesn't seem > > possible. We have task_lock() (a spinlock) held by ptrace_may_access() > > during this call, so preemption should be disabled: > > > > proc_pid_permission() > > has_pid_permissions() > > ptrace_may_access() > > task_lock() > > __ptrace_may_access() > > | security_ptrace_access_check() > > | ptrace_access_check -> selinux_ptrace_access_check() > > | avc_has_perm() ... which does not hit either LSM_AUDIT_DATA_DENTRY nor LSM_AUDIT_DATA_INODE. It's really an unrelated issue. > > preemption enabled). However, it seems like there's another issue here. > > avc_audit() seems to imply that slow_avc_audit() would sleep: > > > > static inline int avc_audit(struct selinux_state *state, > > u32 ssid, u32 tsid, > > u16 tclass, u32 requested, > > struct av_decision *avd, > > int result, > > struct common_audit_data *a, > > int flags) > > { > > u32 audited, denied; > > audited = avc_audit_required(requested, avd, result, 0, &denied); > > if (likely(!audited)) > > return 0; > > /* fall back to ref-walk if we have to generate audit */ > > if (flags & MAY_NOT_BLOCK) > > return -ECHILD; > > return slow_avc_audit(state, ssid, tsid, tclass, > > requested, audited, denied, result, > > a); > > } > > > > If there are other cases in here where we might sleep, it would be a > > problem to sleep with the task lock held, correct? It can sleep - with LSM_AUDIT_DATA_INODE, which is precisely what selinux_inode_permission() is hitting. > I would expect the problem here to be the currently allocated audit > buffer isn't large enough to hold the full audit record, in which case > it will attempt to expand the buffer by a call to pskb_expand_head() - > don't ask why audit buffers are skbs, it's awful - using a gfp flag > that was established when the buffer was first created. In this > particular case it is GFP_ATOMIC|__GFP_NOWARN, which I believe should > be safe in that it will not sleep on an allocation miss. > > I need to go deal with dinner, so I can't trace the entire path at the > moment, but I believe the potential audit buffer allocation is the > main issue. Nope. dput() in dump_common_audit_data(), OTOH, is certainly not safe. OTTH, it's not really needed there - see vfs.git #work.audit for (untested) turning that sucker non-blocking. I hadn't tried a followup that would get rid of the entire AVC_NONBLOCKING thing yet, but I suspect that it should simplify the things in there nicely...