Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp614387pxb; Thu, 30 Sep 2021 13:08:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvXa2QJ24vWHwhPauotLbugCNXfaG68phjdH40fQ7rCUwmSZY76aDMc1r7MVOlc6Y7KhJ6 X-Received: by 2002:a05:6402:1437:: with SMTP id c23mr9514772edx.247.1633032530291; Thu, 30 Sep 2021 13:08:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633032530; cv=none; d=google.com; s=arc-20160816; b=lf/glq0kMBK0jjm7t8mZAWexE4wPXnuCjPqHh6RptvO0pT67L2zCu1E4jvjszdce3m +4zIoC1O3sp1Pqv5J4R9OCgdOjtxAfkecrYojhFJ/V+DROX18267TzlvUxoVsgjVS3Gb +APHXDhgsD83vQJvA3XgIMfrQqj5Oc78Z0YbBsNJjzV+5MeIqIBKtO3FFvbK2SVHMxWZ TysxM5gnrohwcSm/VnfuIrZopcOVt4E8g96YGakdNejrzN+n7rUwhNbml2kBgSgYVseI vaDk/1aIS23fl+GTJ0X1LXySep9C/5Eme4zMOZgnIN9Bq5i7AzeEyvsYbnBlLWfMs6Go c7EA== 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=wtYkkniQkowSl9E85q/Rimm24f70m1X2dA/jUMvBrMA=; b=lRJ6Fr+tpPZ+RkuEWcoTOmg95Wl9wPXVwHgo6RsB9a2nbxee9bOOwNGOMTeyyBBVD9 5RGc2d8Z2woGC+jYHrDSFCLW8ZqcY6aXI2PPu9bdXLUEMQ98yhPbUihLn2niE7ov8a1s FV9R7LAbY/hTCYC1zuYfNWyWcQGsTSWmhiI7wbnKMGpFyiBwaL0yIqu0MSrj5K0Q4G9Y DOR7kD5KTsH4Qska2KEiq3qpC3KMw/ZkMg/itzZL5jp89EPHeePajiZyXU65s7ILwUAI ctkhobnsFzdm6+xsvBxgVANcNQWySY3gtEhorK9WcPdLQGjvEjh21J0yyKXhcPW+nTXr JuNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=cDSzvhcW; 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 mp36si5993453ejc.478.2021.09.30.13.08.24; Thu, 30 Sep 2021 13:08:50 -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=cDSzvhcW; 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 S1344486AbhI3TtJ (ORCPT + 99 others); Thu, 30 Sep 2021 15:49:09 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:30928 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229777AbhI3TtF (ORCPT ); Thu, 30 Sep 2021 15:49:05 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 18UIUK77021687; Thu, 30 Sep 2021 15:47:03 -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=wtYkkniQkowSl9E85q/Rimm24f70m1X2dA/jUMvBrMA=; b=cDSzvhcWQU1QbWAfhGLjbc5TWlScDwgk1AadYvR/wgQ1R0xtQlAxDGrL5sXBkZhm/lRr U5Rx56YCgYY56vgv2oQbpKBtmQoCyH9D3qEwCpK577n6p3fcPUkn4vaYK0/zblbs6hHk OMUrx1hVIZPV+R9K58hIigFgtNzZcbTMbPoCKG0L8wZjEM0j1RpLBlj9ZAcvj2wt9soU iXwffUlRXw84Fic6KTHczxobu1OYbBLGqrH5dmPA2zFdX2DCmGLSMJb7pPLSl5vPMW7L phqYr4+z1bikZQfHiHfGDchi5z7zsFUIde4/xGipVny4OtGJXmBWWFMjoUS6bvbY0Us7 cA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3bdjjxsjv6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 Sep 2021 15:47:03 -0400 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 18UJl2C9024728; Thu, 30 Sep 2021 15:47:02 -0400 Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com with ESMTP id 3bdjjxsjun-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 Sep 2021 15:47:02 -0400 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 18UJhH1r013672; Thu, 30 Sep 2021 19:46:59 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06fra.de.ibm.com with ESMTP id 3b9u1km8cm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 Sep 2021 19:46:59 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 18UJfpQU50200858 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Sep 2021 19:41:51 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3DFAAA4040; Thu, 30 Sep 2021 19:46:57 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0C3FCA4065; Thu, 30 Sep 2021 19:46:56 +0000 (GMT) Received: from li-f45666cc-3089-11b2-a85c-c57d1a57929f.ibm.com (unknown [9.160.140.113]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 30 Sep 2021 19:46:55 +0000 (GMT) Message-ID: <7222772aed3bf4651dc4ed580ade3e6bd33b253d.camel@linux.ibm.com> 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: Thu, 30 Sep 2021 15:46:52 -0400 In-Reply-To: <20210918031139.22674-1-liqiong@nfschina.com> References: <20210827103536.4149-1-liqiong@nfschina.com> <20210918031139.22674-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-ORIG-GUID: -QdY3w3L2IO6evts99gy8Z-XWxegSFBM X-Proofpoint-GUID: 8yvKQxTXdijSxQ18ikb1NVDTCuO_NHrU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-09-30_06,2021-09-30_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 spamscore=0 clxscore=1015 malwarescore=0 suspectscore=0 phishscore=0 mlxlogscore=951 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2109300120 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Liqiong, On Sat, 2021-09-18 at 11:11 +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 > Fixes: 38d859f991f3 ("IMA: policy can now be updated multiple times") > Signed-off-by: Mimi Zohar > Reported-by: kernel test robot > Fix sparse: incompatible types in comparison expression. The "Fix sparse" line shouldn't be on a separate line. Either post the one line fix as a separate patch using the normal "Fixes:" tag or fix the "Reported-by" line, as previously suggested. thanks, Mimi