Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2584299rwb; Mon, 19 Sep 2022 07:11:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7jD11qWlWdAFdjRhkbRq9Z/jarSe8tAapMWncXVRTpFwAOfHo82huNeu/ngANvd+6+/cr0 X-Received: by 2002:a05:6402:847:b0:453:944a:ba8e with SMTP id b7-20020a056402084700b00453944aba8emr10570961edz.326.1663596671265; Mon, 19 Sep 2022 07:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663596671; cv=none; d=google.com; s=arc-20160816; b=iKu43Lm1v2TnvcX2kgR/zyz6kGrIEucwixaJJtoeQ1M5ly1S9yG7il1Mf9e4Og1SiX gXdsfmy2CSM0ZBBGoNL0qpAJ5vfmFUrCxLoKNF+tGtSea4Ph+OTtmi1BJVni9fNdix/+ mioR/j3qjpnCF1zQ4Z5br91dnbCkzrLoEhhJmKSMiNvL2FvcO0oKZKjLgC3R8QiJyK7e CBmdw6IGYL3Ul9d6UtFjmm0OxJzB1uzYEGpLFRb+cHB3Woh4xipteYzeqFHid0y0kXt5 2GIsfzs1zmG65D6bByoe81Ksgj8oheNsypOwoDpG9/fZ5lSJqth3WT3MwdX2wXmq3rvS R4Iw== 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 :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=+t2Fm2xukLMEPHf8ZaJI5wrWDEZGaB6Do9fL6MT3CtM=; b=B9aNAytLn8teK/wNcddF/PI203/+ZIvU/OWV4XpceTZU/hrlMu79ZHj74gjRPvbmiN se/YYUAECtDdhwlNmEB6ZKTyV7eSxAkZP6Lf7eU25xKxdqTkhH5hAm5l2XAOm8P//f44 o5PQWvKZBG/6IJqOTSDuNMBe+cHkSCCozq6zNq8wLnZ1RWpbUae/oQxWlBsBVZEkgAgu iZzZIGUvjICb5vIk3GhbDLq/IOFs4IJFij4eLahOPQZ8V32lr9cDwKLUTdG4nq+j+zMx 5pa8kjkomStz8y6Oor3Z8MWi1Sr8Sqn2W2nHtBSvRtAdkID0izD/DlvSagATNKoSRiqP 3Psw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f8mXZFWY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h15-20020a05640250cf00b0044ed63adce3si10341345edb.397.2022.09.19.07.10.45; Mon, 19 Sep 2022 07:11:11 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f8mXZFWY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230360AbiISNeX (ORCPT + 99 others); Mon, 19 Sep 2022 09:34:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbiISNeU (ORCPT ); Mon, 19 Sep 2022 09:34:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 167781BEBF for ; Mon, 19 Sep 2022 06:34:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663594458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+t2Fm2xukLMEPHf8ZaJI5wrWDEZGaB6Do9fL6MT3CtM=; b=f8mXZFWYv3KvIOs8MEws1vbA/7JKkB88wjBG+Z2HIdkFUMKs8ygQ2NrB7orUsYV6yECk4d 1Ixc7QavKnC0nbb+tuYFvYDY2nvzu/o6Ozo67zgPqvCOlsvcWAunPoiomPSSK3yFWx6zfR +93ey8/ySXCW0ZEGXsIyjxAdBqQip0A= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-648-oeutMdS6M_WTwv6_veBJGQ-1; Mon, 19 Sep 2022 09:34:12 -0400 X-MC-Unique: oeutMdS6M_WTwv6_veBJGQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3F288811E67; Mon, 19 Sep 2022 13:34:11 +0000 (UTC) Received: from [10.18.17.215] (dhcp-17-215.bos.redhat.com [10.18.17.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E10640C6EC2; Mon, 19 Sep 2022 13:34:10 +0000 (UTC) Message-ID: <34b2bb18-ad64-ee10-37ad-3c2ab2387a0e@redhat.com> Date: Mon, 19 Sep 2022 09:34:10 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH] mm/slab_common: fix possiable double free of kmem_cache Content-Language: en-US To: Feng Tang , Vlastimil Babka Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Andrew Morton , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , "kasan-dev@googlegroups.com" References: <20220919031241.1358001-1-feng.tang@intel.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE 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 On 9/19/22 08:50, Feng Tang wrote: > On Mon, Sep 19, 2022 at 05:12:38PM +0800, Vlastimil Babka wrote: >> On 9/19/22 05:12, Feng Tang wrote: > [...] >>> The cause is inside kmem_cache_destroy(): >>> >>> kmem_cache_destroy >>> acquire lock/mutex >>> shutdown_cache >>> schedule_work(kmem_cache_release) (if RCU flag set) >>> release lock/mutex >>> kmem_cache_release (if RCU flag set) >> ^ not set >> >> I've fixed that up. > Oops.. Thanks for catching it! > >>> in some certain timing, the scheduled work could be run before >>> the next RCU flag checking which will get a wrong state. >>> >>> Fix it by caching the RCU flag inside protected area, just like 'refcnt' >>> >>> Signed-off-by: Feng Tang >> Thanks! >> >>> --- >>> >>> note: >>> >>> The error only happens on linux-next tree, and not in Linus' tree, >>> which already has Waiman's commit: >>> 0495e337b703 ("mm/slab_common: Deleting kobject in kmem_cache_destroy() >>> without holding slab_mutex/cpu_hotplug_lock") >> Actually that commit is already in Linus' rc5 too, so I will send your fix >> this week too. Added a Fixes: 0495e337b703 (...) too. > Got it, thanks > > - Feng Thanks for catching this bug. Reviewed-by: Waiman Long Cheers, Longman