Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp810499rwd; Thu, 15 Jun 2023 02:18:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4x2HHW128nWl8ya0nXgCmQSq+6JSAujCrRI9aoj+uUrpy0JqjalIBltkfCtl7ePiGsQMlz X-Received: by 2002:a17:90a:ec0b:b0:25e:93ee:ac0d with SMTP id l11-20020a17090aec0b00b0025e93eeac0dmr849213pjy.42.1686820713940; Thu, 15 Jun 2023 02:18:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686820713; cv=none; d=google.com; s=arc-20160816; b=RCG4X5Nx++XvQxC8dZ4rUJY9FThzLHQw4PRwhFlkkMwEGehiLnDmFHPNGGwvfBg2aB mYEEXXea+TvS/yzAU7HhiHhbGdMoF2P53GRXF5QJ9ve5s+FswhZpCBBx9D/H91WnHp4V 6UtuBysB6zX5CWBOXlM0/NrhfdbzcMs4AlXBlIzUMMjolYLeCSLH9pvv6y1GftfPUyRC fk0rrNt2jVHb5pyOfxAPyx0BEbnFTZm7n1QsPnP5JaEmPtbW0mwL2BYkk78O3G0V9MGa k/iV4iJqKHXcSRTTIT29/NMVvkLB2L45l64IYwrlwYS1+I5/nLMrLh64aHZanIpMMD/e lD7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id; bh=UXEQxlRJFnbDqx8iRURkMYFjrBcOmM+l+RuVp3w9bmQ=; b=bNeK9tdEuXnLuLo08JdYuhuCHmI6io6Pd5BGdtLcTgH5dIFrzoTS5ST5hzRkJ6LhRX buHW12mexQIlWqG79xgsj8mDjL8BHNL8ppBEvR95vlyiIEqZ1dWLJw2bYyhk4Io2CQ90 VbsmjC13hSvJ5qovqXfk4DO9gFVvvowwMEMadgNeXt7x6vKJCymPIjXqTOm+oEjnICL9 wCJY8vTwWZhZjPjM92oI2FT2/fKHrQPRQoqMw/Ak4mUQv5LAKbZz+NfQjdr6iqvRvq01 U4KSDgd2ka8hLSPkg+i1pxOL80xU+GarCjm831cu51bLYRYmH81vTgl5rPi70+SkOPRb 4psQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mi18-20020a17090b4b5200b0024e35ef410fsi13513935pjb.131.2023.06.15.02.18.21; Thu, 15 Jun 2023 02:18:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245420AbjFOJIy (ORCPT + 99 others); Thu, 15 Jun 2023 05:08:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245385AbjFOJIp (ORCPT ); Thu, 15 Jun 2023 05:08:45 -0400 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A82741FE8; Thu, 15 Jun 2023 02:08:37 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=tianjia.zhang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0Vl9wwvH_1686820112; Received: from 30.240.108.67(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0Vl9wwvH_1686820112) by smtp.aliyun-inc.com; Thu, 15 Jun 2023 17:08:34 +0800 Message-ID: <66c72938-912c-5167-fdb1-bffefe1db0c9@linux.alibaba.com> Date: Thu, 15 Jun 2023 17:08:31 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v2] integrity: Fix possible multiple allocation in integrity_inode_get() To: Jarkko Sakkinen , Mimi Zohar , Dmitry Kasatkin , Paul Moore , James Morris , "Serge E. Hallyn" , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230530121453.10249-1-tianjia.zhang@linux.alibaba.com> <20230601064244.33633-1-tianjia.zhang@linux.alibaba.com> Content-Language: en-US From: Tianjia Zhang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jarkko, On 6/9/23 10:24 PM, Jarkko Sakkinen wrote: > On Thu Jun 1, 2023 at 9:42 AM EEST, Tianjia Zhang wrote: >> When integrity_inode_get() is querying and inserting the cache, there >> is a conditional race in the concurrent environment. >> >> The race condition is the result of not properly implementing >> "double-checked locking". In this case, it first checks to see if the >> iint cache record exists before taking the lock, but doesn't check >> again after taking the integrity_iint_lock. >> >> Fixes: bf2276d10ce5 ("ima: allocating iint improvements") >> Signed-off-by: Tianjia Zhang >> Cc: Dmitry Kasatkin >> Cc: # v3.10+ > > s/v3.10/v4.14/ > > I.e. cover only currently maintained longterms, right? > Yes, the race condition was indeed introduced in 3.10, but the fix is estimated to only cover the LTS version. > >> --- >> security/integrity/iint.c | 15 +++++++++------ >> 1 file changed, 9 insertions(+), 6 deletions(-) >> >> diff --git a/security/integrity/iint.c b/security/integrity/iint.c >> index c73858e8c6d5..a462df827de2 100644 >> --- a/security/integrity/iint.c >> +++ b/security/integrity/iint.c >> @@ -43,12 +43,10 @@ static struct integrity_iint_cache *__integrity_iint_find(struct inode *inode) >> else if (inode > iint->inode) >> n = n->rb_right; >> else >> - break; >> + return iint; >> } >> - if (!n) >> - return NULL; >> >> - return iint; >> + return NULL; >> } >> >> /* >> @@ -113,10 +111,15 @@ struct integrity_iint_cache *integrity_inode_get(struct inode *inode) >> parent = *p; >> test_iint = rb_entry(parent, struct integrity_iint_cache, >> rb_node); >> - if (inode < test_iint->inode) >> + if (inode < test_iint->inode) { >> p = &(*p)->rb_left; >> - else >> + } else if (inode > test_iint->inode) { >> p = &(*p)->rb_right; >> + } else { >> + write_unlock(&integrity_iint_lock); >> + kmem_cache_free(iint_cache, iint); >> + return test_iint; >> + } >> } >> >> iint->inode = inode; >> -- >> 2.24.3 (Apple Git-128) > > Mimi, are you picking this? Mimi has picked this patch in next-integrity. > > Off-topic: how do you compile kernel on macOS, you're using VM right? > I'm just interested because I recently bought Mac mini for both > compiling and testing arm64. Optimal would be to be able to compile > the kernel on bare metal and then deploy to a VM... > I am currently only coding and sending the final patch on a Mac. Compilation and testing are still carried out in the linux environment. If you have experience in launching a linux VM on macOS, please share it with me, thanks. Best regards, Tianjia