Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp442076pxb; Thu, 19 Aug 2021 03:23:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9if5XHpGws24BSiOt12d34d0G16PPX9r67Tc4qa1lEDZJ1/jplDwKcbURqEuxhIPcruzY X-Received: by 2002:aa7:c386:: with SMTP id k6mr15292219edq.319.1629368583306; Thu, 19 Aug 2021 03:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629368583; cv=none; d=google.com; s=arc-20160816; b=Y7Bk+cS5fPJOmP9BjCWZUtCJXQM+0CIjRhYzDZkQhhECcuDH1JChsppAXv1YBcHIK+ jOsK4n0TkloywgTBbb5St5R6lS+9KhdxXEuPOvCQRcr6MfWfvzJ+1kunkEjANbBwbykB PUxqXMP8W0FpowsdCsWlBDrl1R3jvKRq7VO1izOzOabGaTXjW7eqOVz/34TcB8gttHyA u5rylzS338hmH9ANkSgQlXdEoNkfmZ3BzvyOhbetafI0QqcXLsob//XYeiWOGaP/LEnh xmzvwdTvvwiPZPUwiy33/3pg41k5k0bm8JzPvQivOS6o6fxKUDP1Rg2ppsEbCXk35Ia+ b53w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=xXtGMA9uYV5kto+jSgsrH5dF896g/6U5Fpl8CZD0vJ4=; b=HJErxHAbP+Q207UsDOju5og7mQC+Hsxu5ZWKjBUqIgdaivUm2mBbvy6ZAdt5gQzNDc V8usWCuwXGoTPbprK/tnGQzdWtiM7fiqRGMrK5nQLJ7c80gh6vGeuECRiqWw45ImKkNg wnKrS7KX/5QoHXxbsvk9NrBdXo5McIrkkZkYDSshZSFx6cDzj34cpe0Q+cfjVF4qbR9/ YORdN8DtwkGhotasaXBpTq/7yZFnmtVlxD18otASlVsEzHrXQE/cSeb7nbvUTcRAIRCf 2SUqWHd6cI+ykcDOcb8TwTnOWu2pm8irPwGOLxBJ3vjcIeDwoVHk+qeG0qU+zShO/3eA rO8Q== 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 j2si2914522eds.437.2021.08.19.03.22.40; Thu, 19 Aug 2021 03:23:03 -0700 (PDT) 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 S237889AbhHSKVo (ORCPT + 99 others); Thu, 19 Aug 2021 06:21:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236149AbhHSKVn (ORCPT ); Thu, 19 Aug 2021 06:21:43 -0400 X-Greylist: delayed 254 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 19 Aug 2021 03:21:07 PDT Received: from ha0.nfschina.com (unknown [IPv6:2400:dd01:100f:2:d63d:7eff:fe08:eb3f]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7380DC061756; Thu, 19 Aug 2021 03:21:07 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by ha0.nfschina.com (Postfix) with ESMTP id 93EACAE0D6B; Thu, 19 Aug 2021 18:17:14 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from ha0.nfschina.com ([127.0.0.1]) by localhost (ha0.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vEz3jAI6unxM; Thu, 19 Aug 2021 18:16:53 +0800 (CST) Received: from localhost.localdomain (unknown [180.167.10.98]) (Authenticated sender: liqiong@nfschina.com) by ha0.nfschina.com (Postfix) with ESMTPA id 9B21AAE0DCB; Thu, 19 Aug 2021 18:16:52 +0800 (CST) From: liqiong To: zohar@linux.ibm.com Cc: dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, liqiong Subject: [PATCH] ima: fix infinite loop within "ima_match_policy" function. Date: Thu, 19 Aug 2021 18:15:29 +0800 Message-Id: <20210819101529.28001-1-liqiong@nfschina.com> X-Mailer: git-send-email 2.11.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When "ima_match_policy" is looping while "ima_update_policy" changs the variable "ima_rules", then "ima_match_policy" may can't exit loop, and kernel keeps printf "rcu_sched detected stall on CPU ...". It occurs at boot phase, systemd-services are being checked within "ima_match_policy,at the same time, the variable "ima_rules" is changed by a service. Signed-off-by: liqiong --- security/integrity/ima/ima_policy.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index fd5d46e511f1..7e71e643457c 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -217,6 +217,7 @@ static LIST_HEAD(ima_default_rules); static LIST_HEAD(ima_policy_rules); static LIST_HEAD(ima_temp_rules); static struct list_head *ima_rules = &ima_default_rules; +static DECLARE_RWSEM(ima_rules_sem); static int ima_policy __initdata; @@ -666,6 +667,7 @@ int ima_match_policy(struct user_namespace *mnt_userns, struct inode *inode, if (template_desc && !*template_desc) *template_desc = ima_template_desc_current(); + down_read(&ima_rules_sem); rcu_read_lock(); list_for_each_entry_rcu(entry, ima_rules, list) { @@ -702,6 +704,7 @@ int ima_match_policy(struct user_namespace *mnt_userns, struct inode *inode, break; } rcu_read_unlock(); + up_read(&ima_rules_sem); return action; } @@ -919,7 +922,9 @@ void ima_update_policy(void) if (ima_rules != policy) { ima_policy_flag = 0; + down_write(&ima_rules_sem); ima_rules = policy; + up_write(&ima_rules_sem); /* * IMA architecture specific policy rules are specified -- 2.11.0