Received: by 10.223.185.116 with SMTP id b49csp868055wrg; Tue, 20 Feb 2018 09:07:33 -0800 (PST) X-Google-Smtp-Source: AH8x227WzXeFvWhOADV0RrRGYIb1jNyY/kF0uuuIPxvhQRdfaq+3GqjfHk5vddIAg1VFMeibIhIW X-Received: by 10.101.83.140 with SMTP id x12mr234967pgq.288.1519146453367; Tue, 20 Feb 2018 09:07:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519146453; cv=none; d=google.com; s=arc-20160816; b=FRwP4qfTR4KZoOkJjDlQMoqqs7Oci86UaWgIGrU3KUkJ78yJKGTwduVuXXpztH0jm8 xBCTXKM6FDtoI+xsBX8RKyIV6OcroQS+Wp72Qt0TQJa6zUNlQJpGL1lbp/bsLRm/msmx fGFcglXq1FDn+x682Vd9+2SE8Ut4aaRkviFcFRrvpfKCsSpySNt96KPOkQ3E0PqQ5Ww4 7SNLM/Ju0gkBWZpWvXAjAr8C8wDNWlH6fJzbPUEEAA2ecKJaucGxOha2MPeEzZVqR6u5 Wlmo5Yzb66zfSDZ9N721zI0rOLrwPLsGemQdrcKlIDCmYim8DHc3xtNuNHrPoWfehqzm fQ2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=8Gyz1lrbxrqYTyrjmsmqTiPpEpPMFGYHCYlApvvq+Jc=; b=UakecBuQ/jZHK8iniWFg1WNpaOGOreaZ4toRSZn5OsNPHZ33BLr8WQrPvHXnA5BOA3 sMi9OpduUc756UBV4glnSXG6E88pcViQfyh89YWv1J2E0swafDbm+jNHxhwOHpAGrTmw VYxZ17/MYYEG58Pxnx98KhSem/Q5q7ol+4+TQ55xLJCoSdB3WzvkTREZtZM2RTmYhaOX YyiIZ7jBNPynb31ubS7cEiRp+SiOmPyyMLWmXB9gyL7ekzdBIPDR26NKvLVAYqq3e4Er mWJVwZ54FlBq8/Ah2gCCOrC2VZ8PO8UUBcK8tk9pRfRZhEoytXoNMGlaWzgxc94r5mB1 CXhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=xRphzJsK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w186si4940641pgd.745.2018.02.20.09.07.18; Tue, 20 Feb 2018 09:07:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=xRphzJsK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753309AbeBTRGb (ORCPT + 99 others); Tue, 20 Feb 2018 12:06:31 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:42578 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752872AbeBTRG3 (ORCPT ); Tue, 20 Feb 2018 12:06:29 -0500 Received: by mail-lf0-f65.google.com with SMTP id t204so5200814lff.9 for ; Tue, 20 Feb 2018 09:06:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=8Gyz1lrbxrqYTyrjmsmqTiPpEpPMFGYHCYlApvvq+Jc=; b=xRphzJsK1r9qzQoIdta4p6qAToxvhaz/xBrF5CN+LGcIjL8WKC5XxEt8zS1rW4qufX Mrzf6mIqv9B07A7Vv6of9nztCB0g7UR31Uk1jjV2V1UpHzsBll97YjZu4RZZrqfW9XE9 pknfT1ADVCJe/i5zLUg8F/HcPKLKVF6UxiBSeIGuIwyZlcQZC/qYuzo2RlwLNd5hF70A rZ2xdaPx6HNfdmCJhn0B1ho9lypcjBboKnjPJAdymEThvWU1EN6MU2sktGZMcTpwpYuC C0zZ0rDfvFM6yEd129vCy4iYidOF8Le9hZgjVX9aty34abBqwXkRyX63kATJxY5SD4mf o+pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=8Gyz1lrbxrqYTyrjmsmqTiPpEpPMFGYHCYlApvvq+Jc=; b=bEt5TCgtrj12gpEedIXPG+xaUcD+A+gWJHg17t8sERT9cntTKt34OyTbz3HeO0VgGs f743jYI/ilQWBWCvd/OsOCRiq3VZLN5WWOk5Dz9KI5xky3VJ0E13nVicsvesvIQqbnXe DXElILE3re4xp0m9p7O7k8+WvrzsAPWjY8V8488EB18KjVFvP04HOoRiFNaNywQb4/iA UinQKsZ8MEml+2/xI+UoZWWFNgs5LrApDNnloXwp7ASDSI0Mh5VEzNpP3txwDL0h+AD2 8cjhYrYVDPoPdo68kjBMqmmt8XeXrbDNIy50WIRhxtppmiTgvZr+7pISiL0NluX7b1B+ /6UA== X-Gm-Message-State: APf1xPB900O3Y8xP6ROqFnosfcp3pmCUxVoV+ClhuXgcrFB3SETy84gI tifrzueDIJAgbKg2ZNM4CYj6ttXbGxly0XYYKhcpwzPnWg== X-Received: by 10.46.5.3 with SMTP id 3mr187855ljf.135.1519146387667; Tue, 20 Feb 2018 09:06:27 -0800 (PST) MIME-Version: 1.0 Received: by 10.25.216.167 with HTTP; Tue, 20 Feb 2018 09:06:26 -0800 (PST) X-Originating-IP: [108.20.156.165] In-Reply-To: <20180220151849.GG25201@hirez.programming.kicks-ass.net> References: <20170328122915.640228468@linuxfoundation.org> <20170328122918.597715642@linuxfoundation.org> <20180220123757.GE25314@hirez.programming.kicks-ass.net> <20180220140640.GE25201@hirez.programming.kicks-ass.net> <20180220151849.GG25201@hirez.programming.kicks-ass.net> From: Paul Moore Date: Tue, 20 Feb 2018 12:06:26 -0500 Message-ID: Subject: Re: [PATCH 4.10 070/111] audit: fix auditd/kernel connection state tracking To: Peter Zijlstra Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, stable@vger.kernel.org, Dmitry Vyukov , linux-audit@redhat.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 20, 2018 at 10:18 AM, Peter Zijlstra wrote: > On Tue, Feb 20, 2018 at 09:51:08AM -0500, Paul Moore wrote: >> On Tue, Feb 20, 2018 at 9:06 AM, Peter Zijlstra wrote: > >> > It's not at all clear to me what that code does, I just stumbled upon >> > __mutex_owner() outside of the mutex code itself and went WTF. >> >> If you don't want people to use __mutex_owner() outside of the mutex >> code I might suggest adding a rather serious comment at the top of the >> function, because right now I don't see anything suggesting that >> function shouldn't be used. Yes, there is the double underscore >> prefix, but that can mean a few different things these days. > > Find below. > >> > The comment (aside from having the most horribly style) ... >> >> Yeah, your dog is ugly too. Notice how neither comment is constructive? > > I'm sure you've seen this one: > > https://lkml.org/lkml/2016/7/8/625 Yep. I stand behind my earlier comment in this thread. >> > Maybe if you could explain how that code is supposed to work and why it >> > doesn't know if it holds a lock I could make a suggestion... >> >> I just spent a few minutes looking back over the bits available in >> include/linux/mutex.h and I'm not seeing anything beyond >> __mutex_owner() which would allow us to determine the mutex owning >> task. It's probably easiest for us to just track ownership ourselves. >> I'll put together a patch later today. > > Note that up until recently the mutex implementation didn't even have a > consistent owner field. And the thing is, it's very easy to use wrong, > only today I've seen a patch do: "__mutex_owner() == task", where task > was allowed to be !current, which is just wrong. Arguably all the more reason why a strongly worded warning is important (which I see you've included below, feel free to include my Reviewed-by). > Looking through kernel/audit.c I'm not even sure I see how you would end > up in audit_log_start() with audit_cmd_mutex held. > > Can you give me a few code paths that trigger this? Simple git-grep is > failing me. Basically look at the code in audit_receive_msg(), but I wasn't asking your opinion on how we should rewrite the audit subsystem, I was just asking how one could determine if the current task was holding a given mutex in a way that was acceptable to you. Based on your comments, and some further inspection of the mutex code, it appears that is/was not something that the core mutex code wants to support/make-visible. Which is perfectly fine, I just wanted to make sure I wasn't missing something before I went ahead and wrote a wrapper around the mutex code for use by audit. FWIW, I just put together the following patch which removes the __mutex_owner() call from audit and doesn't appear to break anything on the audit side (you're CC'd on the patch). It has only been lightly tested, but I'm going to bang on it for a day or so and if I hear no objections I'll merge it into audit/next. * https://www.redhat.com/archives/linux-audit/2018-February/msg00066.html > --- > Subject: mutex: Add comment to __mutex_owner() > From: Peter Zijlstra > Date: Tue Feb 20 16:01:36 CET 2018 > > Attempt to deter usage, this is not a public interface. It is entirely > possibly to implement a conformant mutex without having this owner > field (in fact, we used to have that). > > Signed-off-by: Peter Zijlstra (Intel) > --- > --- a/include/linux/mutex.h > +++ b/include/linux/mutex.h > @@ -66,6 +66,11 @@ struct mutex { > #endif > }; > > +/* > + * Internal helper function; C doesn't allow us to hide it :/ > + * > + * DO NOT USE (outside of mutex code). > + */ > static inline struct task_struct *__mutex_owner(struct mutex *lock) > { > return (struct task_struct *)(atomic_long_read(&lock->owner) & ~0x07); Reviewed-by: Paul Moore -- paul moore www.paul-moore.com