Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1794425pxb; Mon, 23 Aug 2021 05:00:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmcBH2ubQDTP7EjMumPgd6S3LlAJy0WWR3oeRIZgvv976YPftGZ6fcf4H40gkbgw4P8IO1 X-Received: by 2002:a17:906:ced1:: with SMTP id si17mr34329718ejb.506.1629720021458; Mon, 23 Aug 2021 05:00:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629720021; cv=none; d=google.com; s=arc-20160816; b=e3cE+zEavr1Yefgf1wcGbB3NHQZhSvixrhmBB7tlsXkbiVRLTvY0aa1l+YlozR+YIO SrBynd7y3MafiI1DU7GbCJf1p6vxeqvdYo1m4G9Fosv0snGRwerFiPCTP8Eh6cfx1Ct0 95dSsBdOoxIl8gJAzjTguVP52OVorHLSyqwrboO3lzgK8XHPpp3qi9ye333YNOBg+ZBM i+S8Q02Fyus44kqpOdTcVLKvUkMz5gyjWHpS790ELATvoiVZ+V4g6r2EzDnh8dSIrM7J +3B1gRH3tMqyXKIoW9Eitjns5ilEUI584RE4G4aO8u0y3WNiOYMlrquVAOffBeNMr4oY xINA== 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=Iz5i4ZAicf4aU0DCS+OudBoa8Tt/wnm5/hH+U4ImtW8=; b=beI6aFCyzBPXcl9dFLw4l3wFzH/lNO6FipP+yiBsG4RIKb/gj3JJ0Tmjp1eEAlC40E vYaakf47n61io2jS0kpOQCDJhIHDQ6jxXtBNLCd6HBxh4CzwktftWBuHm0ecaErLSPbp T8WmsrKqGQqiQ472butqNrTgJD8M9i0WXLhMQzBx3lVNr0cbX4/djKGxJX99AQUdPRcg TyvS8n9B6Tl6bmDG3POUot0BmVoiB5IIJrcqY+r8WQ7fni1Wkr/NKrwAMLOKaf4bMOqE O5N1AWY5MSttd8Vh4Lqk/2XlQnQUo2i2TqY/FReiwIWg/1TKQU+aLQcvn+qoGKzYff6E CuUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=kAIhI5nR; 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 d22si17360645ejj.387.2021.08.23.04.59.53; Mon, 23 Aug 2021 05:00:21 -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=kAIhI5nR; 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 S235856AbhHWL7D (ORCPT + 99 others); Mon, 23 Aug 2021 07:59:03 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:55588 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230289AbhHWL7C (ORCPT ); Mon, 23 Aug 2021 07:59:02 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17NBer9d074737; Mon, 23 Aug 2021 07:58:07 -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=Iz5i4ZAicf4aU0DCS+OudBoa8Tt/wnm5/hH+U4ImtW8=; b=kAIhI5nRg3uksu4gcZcAHZB1OS1dr+Qnyn/t9NOYguEqYNkleQwAtAgj0qOi7QLqrLJx 5oFIQy1lse+aaCp5M7AE9wAVWbfp0wS3NaA8Zq07UoNKysp/7rv/+lDYYFCozSMEcLaT qb6FPF0RLGs8RNbq2sxPi3m1YEIwXG6ELUHu3KUxbUt+NFfu2rqLclGqAP4hcJMamlJ4 N4EkqE7M2/IC8M1952TdSEtvBcx1ilrbdPoa+0HueOp7Z4kVTqVebUhky3SpVI7e5obi SSqfQtqKInwuRjJDDfEZuN1O9dQCb/f4fF54KR4zuRO0NlAhCrshy8dBBezSsKPbv9Sa 7Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3aketbn23w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Aug 2021 07:58:07 -0400 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17NBg3d5080512; Mon, 23 Aug 2021 07:58:06 -0400 Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 3aketbn236-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Aug 2021 07:58:06 -0400 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17NBlRqS001122; Mon, 23 Aug 2021 11:58:05 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04fra.de.ibm.com with ESMTP id 3ajs48jsf8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Aug 2021 11:58:04 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17NBsNUx19726674 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Aug 2021 11:54:23 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DB53E42064; Mon, 23 Aug 2021 11:58:01 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9D1B442066; Mon, 23 Aug 2021 11:57:59 +0000 (GMT) Received: from sig-9-65-215-209.ibm.com (unknown [9.65.215.209]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 23 Aug 2021 11:57:59 +0000 (GMT) Message-ID: Subject: Re: [PATCH] ima: fix infinite loop within "ima_match_policy" function. From: Mimi Zohar To: THOBY Simon , liqiong 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: Mon, 23 Aug 2021 07:57:58 -0400 In-Reply-To: References: <20210819101529.28001-1-liqiong@nfschina.com> <8d17f252-4a93-f430-3f25-e75556ab01e8@viveris.fr> <1f631c3d-5dce-e477-bfb3-05aa38836442@viveris.fr> <96037695de6125c701889c168550def278adfd4b.camel@linux.ibm.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: 9QsYbkk7545Yp63gPbE_sSc7eneAplqW X-Proofpoint-ORIG-GUID: bPmOxHmBGqHxFt7c_9c3SXKk4WMHQExu X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-23_02:2021-08-23,2021-08-23 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 spamscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108230078 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2021-08-23 at 08:14 +0000, THOBY Simon wrote: > Hi Liqiong, > > On 8/23/21 10:06 AM, liqiong wrote: > > Hi Simon : > > > > Using a temporary ima_rules variable is not working for "ima_policy_next". > > > > void *ima_policy_next(struct seq_file *m, void *v, loff_t *pos) > > { > > struct ima_rule_entry *entry = v; > > - > > + struct list_head *ima_rules_tmp = rcu_dereference(ima_rules); > > rcu_read_lock(); > > entry = list_entry_rcu(entry->list.next, struct ima_rule_entry, list); > > rcu_read_unlock(); > > (*pos)++; > > > > - return (&entry->list == ima_rules) ? NULL : entry; > > + return (&entry->list == ima_rules_tmp) ? NULL : entry; > > } > > > > It seems no way to fix "ima_rules" change within this function, it will alway > > return a entry if "ima_rules" being changed. > > - I think rcu_dereference() should be called inside the RCU read lock > - Maybe we could cheat with: > return (&entry->list == &ima_policy_rules || &entry->list == &ima_default_rules) ? NULL : entry; > as that's the only two rulesets IMA ever use? > Admittedly, this is not as clean as previously, but it should work too. > > The way I see it, the semaphore solution would not work here either, > as ima_policy_next() is called repeatedly as a seq_file > (it is set up in ima_fs.c) and we can't control the locking there: > we cannot lock across the seq_read() call (that cure could end up be > worse than the disease, deadlock-wise), so I fear we cannot protect > against a list update while a user is iterating with a lock. > > So in both cases a cheat like "&entry->list == &ima_policy_rules || &entry->list == &ima_default_rules" > maybe need to be considered. > > What do you think? Is this an overall suggestion or limited to just ima_policy_next()? thanks, Mimi