From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4187C54EE9 for ; Mon, 19 Sep 2022 13:34:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 65F856B0071; Mon, 19 Sep 2022 09:34:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E53D940007; Mon, 19 Sep 2022 09:34:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4609D6B0073; Mon, 19 Sep 2022 09:34:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 38AC96B0071 for ; Mon, 19 Sep 2022 09:34:19 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1D1B6C11B6 for ; Mon, 19 Sep 2022 13:34:19 +0000 (UTC) X-FDA: 79928929038.07.EF63A4B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id ABD4D200A5 for ; Mon, 19 Sep 2022 13:34:18 +0000 (UTC) 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663594458; a=rsa-sha256; cv=none; b=2kk7qhN1wC6DMJYgFs+hz0FAh5klfEijXrJHpNB68GuCipG1zPCq2zH0d8VTYBZ+lRt79/ wEFOGVLEE/FGYCcUtTH2BXThlmUYR2AvAZ4tgEdcyuzDNZ1hJtbltuGdIzcdndNHP7GBRb bCAeQILm6hIY6Njnl/EaNRiygTfPSAc= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f8mXZFWY; spf=pass (imf03.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663594458; h=from:from:sender: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:dkim-signature; bh=+t2Fm2xukLMEPHf8ZaJI5wrWDEZGaB6Do9fL6MT3CtM=; b=hL64p3mWKo+AYiJljHN1Eq/CnY4a4BVle5988tgfOraCgzGVx/xzjISAgKYm5jNiXDpEQw iFAPPbGD7EjgjvQpl/Kd7CNEgocXmVOqYW9tNVYhhukyuwwmVusJdR2JZrPyXcUJpgGkfM snHlMJDd6wQDw+7AcZBc09FD28I4S3w= X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: ABD4D200A5 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f8mXZFWY; spf=pass (imf03.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: 5ea8frmkkocm7e8br15i4ck9gm1px3h7 X-HE-Tag: 1663594458-649161 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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