Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3546024ioo; Mon, 30 May 2022 04:41:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybYjm0MVCdy450hYjM5zhoUfo20Y6sNxeJGXVDKYryQL4HN3rzqvu8J47RF3R7DIMIdcrV X-Received: by 2002:a17:906:9e83:b0:6fe:9f59:a4a4 with SMTP id fx3-20020a1709069e8300b006fe9f59a4a4mr45323320ejc.163.1653910906575; Mon, 30 May 2022 04:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653910906; cv=none; d=google.com; s=arc-20160816; b=yp+wdvZolBGIarqapX9J2ksjN9MsAbngFzuGVYQtdE3uNVpnHKbUDXBH6jIZuhLu56 F7VcZMI4F6DIAsj8RDhGjfULTC/6Fg2pwDmKwVex3qGxJyDI0d4S3POvSGC2FYoJCdvR ZpW6a+m7QnQ3vRHWhgfGEjRuLiHtG5RQnF4FVDRxJlXFXdm2fqYgSXghPetQAaSNxpfG kdmwKIlDr29GunajhLvm6CyGKBeA1fmuZmBwpAH1U5RnHW1/pjS0ya8GnhvARQp6IP1h +rMKJJV6U049Zpu9tgl8x3DBo9QzBpdV5EBT/h5V8kyHIiS44PbjflI3BfPhkWYvt/ZH oF7g== 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 :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=Sa2UmNF2oMi53vg8Q5rSsHt/HYB4lW6/nqq4AMUDDrA=; b=bz8/ttApo11ZVGZ6AOr6iQ0a1WVAauuBmK3+HNSsACjI88oP59ie/zTYDdd1mLWvFY Ebxkfv/daDtQljzGhEgMaAIvD6WDXUzj9TOpJciVgNFGGAJsdD5mun/tctVjJEhw3vQV t755nS1MzBbDqPrwlOS0AwxQ456RlBr76B/azZIdHT4I6qRXDuABABibKF1M6jt/zYDL s52mRYVcXgikciYnrYvsVG3iayUtfxAmXr2uVFxOn9gxdYTxDk+254XGJ/nCl11PSsBq HvaKlawoo70IGbIpp1AQDoi6GrEwxDwgPzhA1TeQ05V+Qy8jni9wr0lSzndbjcYntMi4 OxnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jOhWu4W9; 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 ht12-20020a170907608c00b006fef7d43e6esi13642816ejc.466.2022.05.30.04.41.21; Mon, 30 May 2022 04:41:46 -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=jOhWu4W9; 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 S233140AbiE3G4O (ORCPT + 99 others); Mon, 30 May 2022 02:56:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232915AbiE3G4M (ORCPT ); Mon, 30 May 2022 02:56:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2097471A11 for ; Sun, 29 May 2022 23:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653893765; 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=Sa2UmNF2oMi53vg8Q5rSsHt/HYB4lW6/nqq4AMUDDrA=; b=jOhWu4W96yb5jqZPN0/lhvWZyPn2kH6ZkcJAopWMOYqUmDDSS9/xK69abS9iWiTVCXr0B4 qC+c+d8AjGtwGbnk9A9iDFK52tN90lVYIT9qXjPknCGAgGRtGaeHnoyLyfN+13Y8uBVTMv X1LbGxEpR38TtwZ3z4kS1+CwajAcyZI= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-119-bL_BN9sjMxCRGXbIih-mVA-1; Mon, 30 May 2022 02:56:02 -0400 X-MC-Unique: bL_BN9sjMxCRGXbIih-mVA-1 Received: by mail-wm1-f72.google.com with SMTP id k5-20020a05600c0b4500b003941ca130f9so4172290wmr.0 for ; Sun, 29 May 2022 23:56:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=Sa2UmNF2oMi53vg8Q5rSsHt/HYB4lW6/nqq4AMUDDrA=; b=roUG+gr2nY3IU9uOywjrAhzgFfylJ6d6V6xSaJu7rvVBXeCsGnoy3a+Ok6uhBL1d9q EivnG38YNPF4FpECGohvv7Gay3x0UNOau1cJ9WqiMoay+nnq8lAtRbEFIQLi6bmFuoCJ S5JS7Sz2kZj9j5UnR2cvaHP3yi9VvdG/5xyNbrVbBs1S3FsgBWe513LhyTxygfWMnHUF 4bBIFtLxafRT4IXTkrJp3dzJC+gnWv09pUVdsAYdTbzlzgVdspdmNLj4RiwnKs9iwUF7 rQKsrbDajFBJ5qUmFZrh3WpDOxEmjDtoTTDz3N1w9HGg4gZ/XwBIYvPypLEGuWqnKx8d 9H3A== X-Gm-Message-State: AOAM532UU/9mrDqkmJALqtYLOwO8JorAgJKQAlyzSYlCIH//sU6jQDsZ MNg4gksJ+YynlCB+wEWaa7CREBHZX1G2knS95FvRp0sww1prgMC8etUSRpM4rlnvPdslp99Xoj+ 7heby/DXlYGbCIfmOtYxy70vg X-Received: by 2002:a7b:c1cd:0:b0:397:30fb:5378 with SMTP id a13-20020a7bc1cd000000b0039730fb5378mr17441372wmj.115.1653893761574; Sun, 29 May 2022 23:56:01 -0700 (PDT) X-Received: by 2002:a7b:c1cd:0:b0:397:30fb:5378 with SMTP id a13-20020a7bc1cd000000b0039730fb5378mr17441364wmj.115.1653893761312; Sun, 29 May 2022 23:56:01 -0700 (PDT) Received: from ?IPV6:2003:cb:c704:7c00:aaa9:2ce5:5aa0:f736? (p200300cbc7047c00aaa92ce55aa0f736.dip0.t-ipconnect.de. [2003:cb:c704:7c00:aaa9:2ce5:5aa0:f736]) by smtp.gmail.com with ESMTPSA id e9-20020adfe389000000b0020c5253d8fcsm9690559wrm.72.2022.05.29.23.56.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 May 2022 23:56:00 -0700 (PDT) Message-ID: <0563a019-09e3-a176-d4c1-c240f3cf62d0@redhat.com> Date: Mon, 30 May 2022 08:55:59 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH] mm: memory_hotplug: fix memory error handling Content-Language: en-US To: Muchun Song , gregkh@linuxfoundation.org, rafael@kernel.org, cheloha@linux.vnet.ibm.com, mhocko@suse.com, akpm@linux-foundation.org, nathanl@linux.ibm.com Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20220530053326.41682-1-songmuchun@bytedance.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220530053326.41682-1-songmuchun@bytedance.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.7 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_NONE,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 30.05.22 07:33, Muchun Song wrote: > The device_unregister() is supposed to be used to unregister devices if > device_register() has succeed. And device_unregister() will put device. > The caller should not do it again, otherwise, the first call of > put_device() will drop the last reference count, then the next call > of device_unregister() will UAF on device. > > Fixes: 4fb6eabf1037 ("drivers/base/memory.c: cache memory blocks in xarray to accelerate lookup") > Signed-off-by: Muchun Song > Cc: > --- > drivers/base/memory.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/base/memory.c b/drivers/base/memory.c > index 7222ff9b5e05..084d67fd55cc 100644 > --- a/drivers/base/memory.c > +++ b/drivers/base/memory.c > @@ -636,10 +636,9 @@ static int __add_memory_block(struct memory_block *memory) > } > ret = xa_err(xa_store(&memory_blocks, memory->dev.id, memory, > GFP_KERNEL)); > - if (ret) { > - put_device(&memory->dev); > + if (ret) > device_unregister(&memory->dev); > - } > + > return ret; > } > See https://lkml.kernel.org/r/d44c63d78affe844f020dc02ad6af29abc448fc4.1650611702.git.christophe.jaillet@wanadoo.fr -- Thanks, David / dhildenb