Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp224368pxb; Thu, 26 Aug 2021 01:21:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBMysoqVIDhdmgARYf08bEH2LC0b6UAQcqf8RuRJFG679OXRbVyrfNS2WlhSIn2rdXxzOo X-Received: by 2002:a50:cdcb:: with SMTP id h11mr3048174edj.366.1629966075444; Thu, 26 Aug 2021 01:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629966075; cv=none; d=google.com; s=arc-20160816; b=melDvQ70vcQUO5SRKVfgRppu7oW7r2wnIbNK0SvkGi7Wcdw2YX376OouGKdqGQUaFT tkovOV7hDuK4ufov2IrdYG/GqkY821huDNXZwHmu+epMd7H9KwoQxZk+95cO9ODLNuZY 6ygTk+c1x/6EpiG4r7Iq55v2CDCSdBgbwm3Ms+Eh/EIjv7TrZ0ka1BMDs8OX4bxGb4bT nNosCWjmQxMTbBmjvvB7aRruNzmJReKbA7QhL7md+2GrUWgKfHw1uURzeBZR0cwH0vag qXzrNgSsQv8sP7xUICY351St132rzpin9baUPQboppUmiID/XypGd+yCcee/2RkBVdGm CT2Q== 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:references:cc :to:subject:from; bh=2kflyp6fzr3+hyEmWpK3TtftIiV7Z+O68q9lOPPzszg=; b=gkLUTxluQgyIDV/yVhSUWAfBa/WbW49FzeMbmMJSdXZFYiz0c/9p/PJ0BlUV6U5SwL 8Nu3TBcAgsoW5Kt/GtKecpwbR+K7kv5t0Ph8kARrXLHQa4OjaLY3JAFE6rHFKYqropr9 7wEq9eer0jdAoX94O+QReNCagIpwXNBeruCJ+UJIRmc2WCgUXFB1WpQfPCl++rUKB5nC +Xlp+8fuupPuax25LhN0vy1lr1bcUwsZbCxD3MZrrfu50ukLSgNVa26JGxWrIXZthEP2 pgW/VzdwVwVv6hckPZa/qSi4NCJ02cD7tgDOP6FsJ0yntRkswVEBw6bR+VLLmyiGuqmd AbaA== 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 js14si2521302ejc.188.2021.08.26.01.20.50; Thu, 26 Aug 2021 01:21:15 -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 S240327AbhHZIRC (ORCPT + 99 others); Thu, 26 Aug 2021 04:17:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232992AbhHZIRC (ORCPT ); Thu, 26 Aug 2021 04:17:02 -0400 Received: from ha0.nfschina.com (unknown [IPv6:2400:dd01:100f:2:d63d:7eff:fe08:eb3f]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AF2F4C061757; Thu, 26 Aug 2021 01:16:14 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by ha0.nfschina.com (Postfix) with ESMTP id 8D16BAE0DC7; Thu, 26 Aug 2021 16:15:23 +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 PqZdW8WS1aF3; Thu, 26 Aug 2021 16:15:03 +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 7B218AE0DB6; Thu, 26 Aug 2021 16:15:03 +0800 (CST) From: liqiong Subject: Re: [PATCH] ima: fix deadlock within RCU list of ima_rules To: THOBY Simon , Mimi Zohar 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> <5a032a1b-f763-a0e4-8ea2-803872bd7174@nfschina.com> Message-ID: <1e464ae0-28e1-6511-ab89-52b5cd1a0841@nfschina.com> Date: Thu, 26 Aug 2021 16:15:49 +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: 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 Simon, Thanks for your help, your advice is clear, can i just use it, how about this: The current IMA ruleset is identified by the variable "ima_rules", and the pointer starts pointing at the list "ima_default_rules". When loading a custom policy for the first time, the variable is updated to point to the list "ima_policy_rules" instead. That update isn't RCU-safe, and deadlocks are possible. Introduce a temporary value for "ima_rules" when iterating over the ruleset to avoid the deadlocks. Signed-off-by: liqiong --- 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 Thanks liqiong 在 2021年08月25日 20:03, THOBY Simon 写道: > Hi Liqiong, > > On 8/25/21 1:45 PM, liqiong wrote: >> Hi Mimi, >> >> This copy may be better. >> >> >> subject: ima: fix deadlock when iterating over the init "ima_rules" list. >> >> > As Mimi said, consider adding an introducing paragraph, like: > 'The current IMA ruleset is identified by the variable "ima_rules", > and the pointer starts pointing at the list "ima_default_rules". When > loading a custom policy for the first time, the variable is > updated to point to the list "ima_policy_rules" instead. That update > isn't RCU-safe, and deadlocks are possible.' > >> When traversing back to head, the init "ima_rules" list can't exit >> iterating if "ima_rules" has been 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. > Per the process (see 'Documentation/process/submitting-patches.rst'), > please prefer an imperative style (written in another paragraph): > 'Introduce a temporary value for "ima_rules" when iterating over the ruleset.' > > > Thanks, > Simon