From patchwork Tue Oct 3 18:25:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 114710 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2187093qgn; Tue, 3 Oct 2017 11:25:35 -0700 (PDT) X-Google-Smtp-Source: AOwi7QD3I9Y1hufM3/PH4DA7LTOl5NM09646+N8t08VWfWdSV4OuDYsVsJY1hlGEQK4QT0kpgoWv X-Received: by 10.99.98.197 with SMTP id w188mr5717759pgb.41.1507055135098; Tue, 03 Oct 2017 11:25:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507055135; cv=none; d=google.com; s=arc-20160816; b=04X63W/sOZO65MclIXxVjP2JrCvSWs1qK97RC29p+rNjiTYDGKJkm57OVs1SgrfLW1 DKoG0Blf9xw3O7TYrxjk/rDvtOa69mQC08bHW0mXNIjaXMnTGqQrGg6w891juA35AXg0 FqkRklaTzu7tFtvgQ9pgh7x/+BHLMbdocKrN1CqNT2nWVNRIxxfwmxGTI3g2ekTpQzDY y7LLQWiKhOGRcAPkHaJfFISDcOytkBOWNqAW84qyy3uBX9OonAF0lYUOmJhwpR7Uxbw6 h47VRBrlj5uYegoRxSDIjr1Wcky9cF8yPbFGkrvBgj3yDNF0u6alYIfu7KoK9Zj5S9TE LtnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=iv97o1izemxxKJ7/qp6z2v0RHK9TZo2nMmO6f+WxlN0=; b=b+AdlhNAXx5wRy8HhBxHTDtKqKixJLekmnrdeJa4NLY38iPZW3/sTNoFL7ekrNXM2z Ngk9yUZNd2uuqITMKhkjuSvPkWszaGMzXnhGI0zZb6YG609UBZo/PE+4cMLwJnE2dTxl u3gL4l6T+9OaCsqEpJgEwfVHZDLmDVm5U+dvt0CcPa5EkfZ8hclh4uw4Hk/t1q+thYi4 rRe/19BiLa/lexdaBGUtfvntRVgduIdib64t6qFdla/8xbluXn98DxC++fSA69ijHMPG pdn2eHo5Jru/SzUVKMrZcS7oJmtCK+iYjdTi8LYgUnw4G5FBSWlhaPRlrNVRcyf4XUxH Axnw== ARC-Authentication-Results: i=1; mx.google.com; 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 a5si10682942plh.485.2017.10.03.11.25.34; Tue, 03 Oct 2017 11:25:35 -0700 (PDT) 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; 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 S1751409AbdJCSZd (ORCPT + 26 others); Tue, 3 Oct 2017 14:25:33 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:52462 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750812AbdJCSZa (ORCPT ); Tue, 3 Oct 2017 14:25:30 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3A64380D; Tue, 3 Oct 2017 11:25:30 -0700 (PDT) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0C8CD3F578; Tue, 3 Oct 2017 11:25:30 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id B3DF61AE2DCF; Tue, 3 Oct 2017 19:25:30 +0100 (BST) From: Will Deacon To: linux-kernel@vger.kernel.org Cc: paulmck@linux.vnet.ibm.com, Will Deacon , Peter Zijlstra Subject: [PATCH v2 1/4] security/apparmor: Replace homebrew use of write_can_lock with lockdep Date: Tue, 3 Oct 2017 19:25:26 +0100 Message-Id: <1507055129-12300-1-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The lockdep subsystem provides a robust way to assert that a lock is held, so use that instead of write_can_lock, which can give incorrect results for qrwlocks. Cc: Peter Zijlstra Acked-by: John Johansen Signed-off-by: Will Deacon --- security/apparmor/include/lib.h | 11 ----------- security/apparmor/label.c | 8 ++++---- 2 files changed, 4 insertions(+), 15 deletions(-) -- 2.1.4 diff --git a/security/apparmor/include/lib.h b/security/apparmor/include/lib.h index 436b3a722357..f546707a2bbb 100644 --- a/security/apparmor/include/lib.h +++ b/security/apparmor/include/lib.h @@ -19,17 +19,6 @@ #include "match.h" -/* Provide our own test for whether a write lock is held for asserts - * this is because on none SMP systems write_can_lock will always - * resolve to true, which is what you want for code making decisions - * based on it, but wrong for asserts checking that the lock is held - */ -#ifdef CONFIG_SMP -#define write_is_locked(X) !write_can_lock(X) -#else -#define write_is_locked(X) (1) -#endif /* CONFIG_SMP */ - /* * DEBUG remains global (no per profile flag) since it is mostly used in sysctl * which is not related to profile accesses. diff --git a/security/apparmor/label.c b/security/apparmor/label.c index c5b99b954580..ad28e03a6f30 100644 --- a/security/apparmor/label.c +++ b/security/apparmor/label.c @@ -80,7 +80,7 @@ void __aa_proxy_redirect(struct aa_label *orig, struct aa_label *new) AA_BUG(!orig); AA_BUG(!new); - AA_BUG(!write_is_locked(&labels_set(orig)->lock)); + lockdep_assert_held_exclusive(&labels_set(orig)->lock); tmp = rcu_dereference_protected(orig->proxy->label, &labels_ns(orig)->lock); @@ -571,7 +571,7 @@ static bool __label_remove(struct aa_label *label, struct aa_label *new) AA_BUG(!ls); AA_BUG(!label); - AA_BUG(!write_is_locked(&ls->lock)); + lockdep_assert_held_exclusive(&ls->lock); if (new) __aa_proxy_redirect(label, new); @@ -608,7 +608,7 @@ static bool __label_replace(struct aa_label *old, struct aa_label *new) AA_BUG(!ls); AA_BUG(!old); AA_BUG(!new); - AA_BUG(!write_is_locked(&ls->lock)); + lockdep_assert_held_exclusive(&ls->lock); AA_BUG(new->flags & FLAG_IN_TREE); if (!label_is_stale(old)) @@ -645,7 +645,7 @@ static struct aa_label *__label_insert(struct aa_labelset *ls, AA_BUG(!ls); AA_BUG(!label); AA_BUG(labels_set(label) != ls); - AA_BUG(!write_is_locked(&ls->lock)); + lockdep_assert_held_exclusive(&ls->lock); AA_BUG(label->flags & FLAG_IN_TREE); /* Figure out where to put new node */