Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1459488pxb; Fri, 27 Aug 2021 09:17:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcv6CipHrl9CvGCTklKVIcNJhrCN1J7Xz8VOTizTtlVTAYl6BTOEQvkRmwqYH8jY9/ew9k X-Received: by 2002:a05:6e02:1888:: with SMTP id o8mr7172206ilu.124.1630081072617; Fri, 27 Aug 2021 09:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630081072; cv=none; d=google.com; s=arc-20160816; b=PjOY4lBAsQZpD32Ra4e0sRQx30TrRqMW3uspsFZ6qanqWw/MEadEOCNl9bQUfwWR61 3oyMGl99BmJWjOFfDNu+5lRVdF99s/cbBC0wLAK3GJlI5zCQoNGRpYTMNYyIPR68/wFI PLmrcNu7AwMa9pAW6bUy34qM2NpIv17Zl1WC7bqi9wsIaYLA+gh6NWuEpEUvaFxv7cHO PCOEqNUvgfed7SFBUt7+4s1gM6WDSjXQ9BHQBe4RlaAxExFMTtpTq3dHXtR4r2QsLrvR Y1vHv8e89Jdwqpw0PQRqLv15/uYdeVc/SZpjLqiQpBuwjWx0uKWfWH5INEVOuo8SI5Xv wfuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature; bh=nvvnLdxHi7PTLSadgbA728cuJKrqqjfzeSllbtHLFwg=; b=GDQyZiut0oEVaVZKwwgCQ38jZKm9mt9Iv7wRlnW8i06ZJwuiDXMj+SInnNQRvQaYT3 f90ps0w+g10o3O0TICrupZkynaJnBGlBgAWf2mt7XC24g0EPMaD8A1avTIpUjmuQXJiJ DZbUK7K61HuQc4lca6TT5+Ib0MCvSmlRqInlPDGVgD+u9rLBBKU9pnAcw7LMNjU8SGC2 zHc3qfDbTbmWs0TgQmTVANLO6hPgVr2cCdW860OMduHJlwxgtMjwgZrIfrISn6JjgVV3 CoMmThm93Yj8niUNSYLqyfQnJDmK6Mc9ArdcuX5qQ2RHA1NPyH5l0WIzJOEQFN1KAjui PM8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=bRPh6DXN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c26si6181566jam.74.2021.08.27.09.17.39; Fri, 27 Aug 2021 09:17:52 -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; dkim=pass header.i=@ibm.com header.s=pp1 header.b=bRPh6DXN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245447AbhH0QRS (ORCPT + 99 others); Fri, 27 Aug 2021 12:17:18 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:15484 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234192AbhH0QRR (ORCPT ); Fri, 27 Aug 2021 12:17:17 -0400 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17RG434C127152; Fri, 27 Aug 2021 12:16:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=nvvnLdxHi7PTLSadgbA728cuJKrqqjfzeSllbtHLFwg=; b=bRPh6DXN+iqWxDAajTfq6mvDn+33+aHUbZnVandpm/87hKnEFu8yXu0nu0O0S5TEAuW3 PAZDoBT4LJO4W6Mib3dQUamET3aU4CoJKn7xjrs+FJJIxQFjObzLqpW/x0J2hbGG48J0 km3554ftQX9bCS2eKmnW6IXgyMAbaRoQCr0pib97XG7NhFxWxARhEMMUtqFGsS3B5lyP g0XIqnUOWTrff3jrPKE9j7txvP7jbFnztybJMVa01MK8BwJtLse+ParcOYPVfKfz6lG4 dyp0P3pFaAJhBcWYP8hyz4uyxtQWhFw0L3WzdRFUl1YCgZpWE/zTe16eSjKLX545b5cm 4A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3aq36n8fpf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 12:16:14 -0400 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17RG47jM127343; Fri, 27 Aug 2021 12:16:13 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 3aq36n8fnp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 12:16:13 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17RGDauT026077; Fri, 27 Aug 2021 16:16:11 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma03ams.nl.ibm.com with ESMTP id 3ajs48kshj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 16:16:11 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17RGG8bM56754632 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 16:16:09 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CE2FE52063; Fri, 27 Aug 2021 16:16:08 +0000 (GMT) Received: from sig-9-65-233-113.ibm.com (unknown [9.65.233.113]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 281AE5204E; Fri, 27 Aug 2021 16:16:06 +0000 (GMT) Message-ID: Subject: Re: [PATCH] ima: fix deadlock when traversing "ima_default_rules". From: Mimi Zohar To: liqiong , Simon.THOBY@viveris.fr 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 Date: Fri, 27 Aug 2021 12:16:06 -0400 In-Reply-To: <20210827103536.4149-1-liqiong@nfschina.com> References: <20210824085747.23604-1-liqiong@nfschina.com> <20210827103536.4149-1-liqiong@nfschina.com> Content-Type: text/plain; charset="ISO-8859-15" X-Mailer: Evolution 3.28.5 (3.28.5-16.el8) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: rFWXgPAAdNyGze5lqKH2wWr8KROvEFWO X-Proofpoint-ORIG-GUID: XT8JGzVNTy6U3pv_9f6kFkeNfTDlgHLF X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-27_04:2021-08-26,2021-08-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 bulkscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 clxscore=1015 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270096 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2021-08-27 at 18:35 +0800, liqiong wrote: > The current IMA ruleset is identified by the variable "ima_rules" > that default to "&ima_default_rules". When loading a custom policy > for the first time, the variable is updated to "&ima_policy_rules" > instead. That update isn't RCU-safe, and deadlocks are possible. > Indeed, some functions like ima_match_policy() may loop indefinitely > when traversing "ima_default_rules" with list_for_each_entry_rcu(). > > When iterating over the default ruleset back to head, if the list > head is "ima_default_rules", and "ima_rules" have been updated to > "&ima_policy_rules", the loop condition (&entry->list != ima_rules) > stays always true, traversing won't terminate, causing a soft lockup > and RCU stalls. > > Introduce a temporary value for "ima_rules" when iterating over > the ruleset to avoid the deadlocks. > > Signed-off-by: liqiong > Reviewed-by: THOBY Simon Thank you, Liqiong, Simon. This patch set is now queued in the next- integrity-testing branch. Mimi