Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp180785pxb; Wed, 25 Aug 2021 00:08:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsquZ0ZWt0GuABP9Qc3WMMTwFEwKIGlcT8KNSs9nHcbq4+wYuDzGnk5A51oCHDU9ZUJ5LU X-Received: by 2002:a50:d68e:: with SMTP id r14mr47934305edi.136.1629875311711; Wed, 25 Aug 2021 00:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629875311; cv=none; d=google.com; s=arc-20160816; b=lhZQdIpjhrXresB7hvIY7/N2GFtNddTV60j9xYimLsCC2Oh7XpLyw2+hUI57ct8jC6 s1JKF+bMWCKzDr/iaAiUcDiX1Pc0rdwAe30bTwE3LQEHmkzgaRUphP4awRmeay2WAkX9 J92vcTkpQRB4u0SyAz1q0ZOqtRT2SB7d77jP7TVO8aUPO9gB1wqfQckB1/k4hA2pimr0 rsQGH4fgcSm2DeICEeqg8mSU/zNg3kWGDeE8a0YjNLhSUNxM9nWGTvmLwi4KkisM4w7N TEr++Tl0XGHN3Sv1U8Z7FBFlZByP0OoFZEHcTyhDq9FfJZS5fZImgExrVEafpqYhMWVe ivyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=kSdVRrJVgfhgIx1X7uGxujRQh9FRFwxPHybKRwmLTP8=; b=lR2rO3Yi0M9OiUqC9byM1yS2YmucgRgSiUa0lGj4ha98k9zdP+gAOh0rgagWlg5beC Nujwp7lD3QpDiexd3syfezXJmlfJ+OwEkPRbclCX8O+NCvC7JdWfTEcS9FbOFQ0a2yTc 3MsJCxogL+xE9Ptn+yahGCOfqjb/wnHJ5pr/4hguXtvKe0E5ihTO51mhp+j+dSxFnqBw EFiQtICQfW3DILhyLmMkesU46BfCo9Gm98rNsSN+Z+hd3MR+ch91PzyxFxMSmRRWJ4k3 p5tQ9mv4ipMzJZViX4bqZmeY1I3s/5/qvhDc8E9fF2maHgE4GxwFBBs+gMekuRCgM3jK nrhg== 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 z7si11777272edp.521.2021.08.25.00.07.49; Wed, 25 Aug 2021 00:08:31 -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 S238764AbhHYHGw (ORCPT + 99 others); Wed, 25 Aug 2021 03:06:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238318AbhHYHGv (ORCPT ); Wed, 25 Aug 2021 03:06:51 -0400 Received: from ha0.nfschina.com (unknown [IPv6:2400:dd01:100f:2:d63d:7eff:fe08:eb3f]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 932C0C061757; Wed, 25 Aug 2021 00:06:05 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by ha0.nfschina.com (Postfix) with ESMTP id E6365AE0DE1; Wed, 25 Aug 2021 15:05:25 +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 LCRAHL2YDaox; Wed, 25 Aug 2021 15:05:07 +0800 (CST) Received: from [172.30.18.174] (unknown [180.167.10.98]) (Authenticated sender: liqiong@nfschina.com) by ha0.nfschina.com (Postfix) with ESMTPA id C8F28AE0D1B; Wed, 25 Aug 2021 15:05:06 +0800 (CST) Subject: Re: [PATCH] ima: fix deadlock within RCU list of ima_rules To: Mimi Zohar , THOBY Simon 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" References: <20210819101529.28001-1-liqiong@nfschina.com> <20210824085747.23604-1-liqiong@nfschina.com> <3ba4da9d-fa7b-c486-0c48-67cee4d5de6d@nfschina.com> <2c4f61ff68544b2627fc4a38ad1e4109184ec68a.camel@linux.ibm.com> From: liqiong Message-ID: Date: Wed, 25 Aug 2021 15:05:42 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <2c4f61ff68544b2627fc4a38ad1e4109184ec68a.camel@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mimi, Thanks for the advice,maybe i should trim the message, here is a new copy: subject: ima: fix deadlock when iterating over the init "ima_rules" list. The init "ima_rules" list can't traverse back to head, if "ima_rules" is being updated to "ima_policy_rules". It causes soft lockup and RCU stalls. So we can introduce a duplicate of "ima_rules" for each "ima_rules" list loop. Signed-off-by: liqiong --- This problem can happen in practice: updating the IMA policy in the boot process while systemd-services are being checked. security/integrity/ima/ima_policy.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index fd5d46e511f1..e92b197bfd3c 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c Regards, liqiong 在 2021年08月24日 20:38, Mimi Zohar 写道: > On Tue, 2021-08-24 at 20:09 +0800, liqiong wrote: >> Hi Simon : >> >> ima: fix deadlock within RCU list of ima_rules. >> > Before the following paragraph, an introductory sentence is needed. > Try adding a sentence to the affect that "ima_rules" initially points > to the "ima_default_rules", but after loading a custom policy points to > the "ima_policy_rules". Then describe the bug at a high level, > something like - transitioning to the "ima_policy_rules" isn't being > done safely. > > Followed by the details. > >> ima_match_policy() is looping on the policy ruleset while >> ima_update_policy() updates the variable "ima_rules". This can >> lead to a situation where ima_match_policy() can't exit the >> 'list_for_each_entry_rcu' loop, causing RCU stalls >> ("rcu_sched detected stall on CPU ..."). >> >> This problem can happen in practice: updating the IMA policy >> in the boot process while systemd-services are being checked. >> >> In addition to ima_match_policy(), other function with >> "list_for_each_entry_rcu" should happen too. Fix locking by >> introducing a duplicate of "ima_rules" for each >> "list_for_each_entry_rcu". >> >> >> How about this commit message ? >> >> I have tested this patch in lab, we can reproduced this error case, >> have done reboot test many times. This patch should work. > The above comment doesn't belong in the commit message, but is a > message to the reviewers/maintainers and goes after the patch > descriptions three dashes line. > > thanks, > > Mimi > >