Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2199769iof; Tue, 7 Jun 2022 23:01:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeITdylv/3ngJn96+tTEZ3DKucEOQV6C3qPu/nyLIxbGkbUBbcKHNUNFJRDkRbmAAoZmMI X-Received: by 2002:a17:903:2485:b0:161:da96:1701 with SMTP id p5-20020a170903248500b00161da961701mr32878932plw.58.1654668060953; Tue, 07 Jun 2022 23:01:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654668060; cv=none; d=google.com; s=arc-20160816; b=keZ4HW+oNaGOng1ICXwsuw5g7AooVoP+76p2BhqRcOZjYbE6MleT0borExurWzzGty XZ3j6cLyVrii6IDMEZoCjdhLQlB3PHC585nry57KD34AyCJI09hqa1pMmYuIAE/mYweA z4TeqKGNQZ2c63q2oxo2ZTSd+0XhZhfJwtvKan8eXBnAGZ0ppCrLTwK91AoVVfZvouB7 oM58L9VHlejTO96Ga8cZr48w3e7IBQvBuczUag1bRXOpdi/D8sTTxloT+DN02K+VY2IQ CNhqWE98ANj+1FbRgQ5ZNjRViafPikbh3iUDS3/hSu1oHAQ4aBwCO8sImp3o25B93T/k jTSw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AXJtcq+RPkMV1TTOXbz7x5faS1Gtx+RNB/f6iLaWyws=; b=w0+9vBufj7ZFNpNyFU8QcV/pjjirk1jRYuqKWdCPOKX8GPAs647xo0y0png58L/uuI CefIWRPq/bD5dR4yqKS/yHgK/SUO5jAPjJ+kYQ1xY5RAOWffRgAXHrOBmbjaiUe6MIYD sI6DWEaEJxig4dLWfIzy2vvHIIuLBz1Pt6Fg3wqUq6CusnZXC4OlLULSMl4BcWoSJ8qB A+yvK6wzTH44j/Dld+4NYudgq653QQ/AwHOGxmSqUfg7olpvx13ytPEfT0HVMjROn+Dv 79ugNkFSV+mtxhkSW3E10EqMlygDt2v6Di1Znpx63wqijmTzIbdWVxrXKuic/P4r9AT+ 8PZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Syg7k/xg"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id lp15-20020a17090b4a8f00b001e049d7ca99si3080044pjb.138.2022.06.07.23.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:01:00 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Syg7k/xg"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 521AE4B928E; Tue, 7 Jun 2022 22:25:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237759AbiFHBJG (ORCPT + 99 others); Tue, 7 Jun 2022 21:09:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384255AbiFGVyX (ORCPT ); Tue, 7 Jun 2022 17:54:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1439824A1D8; Tue, 7 Jun 2022 12:13:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 66621618D9; Tue, 7 Jun 2022 19:12:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E574C385A2; Tue, 7 Jun 2022 19:12:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629174; bh=42ZT3DX00fIum0t1J+6Opa8Rq3Y6zavv3Rpl3Ycz3gg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Syg7k/xgpHVND+7qrDwZ79WEDkMSqSAafXeql+Q0hlmPtd2pQEwzrd3y6iW6P1w40 qm0UKmVXX8o5NRkhvk6ytn24USCcZP0fF1SW1oW2P1sD9Shlt/fFq5pbIdK2g0lC3R URPFzKbW3b/+QuubryOItXZVdAUdemt2OTiwYOxY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe JAILLET , Michal Hocko , David Hildenbrand , "Rafael J. Wysocki" , Scott Cheloha , Nathan Lynch , Andrew Morton , Sasha Levin Subject: [PATCH 5.18 597/879] drivers/base/memory: fix an unlikely reference counting issue in __add_memory_block() Date: Tue, 7 Jun 2022 19:01:55 +0200 Message-Id: <20220607165020.182006756@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_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 From: Christophe JAILLET [ Upstream commit f47f758cff59c68015d6b9b9c077110df7c2c828 ] __add_memory_block() calls both put_device() and device_unregister() when storing the memory block into the xarray. This is incorrect because xarray doesn't take an additional reference and device_unregister() already calls put_device(). Triggering the issue looks really unlikely and its only effect should be to log a spurious warning about a ref counted issue. Link: https://lkml.kernel.org/r/d44c63d78affe844f020dc02ad6af29abc448fc4.1650611702.git.christophe.jaillet@wanadoo.fr Fixes: 4fb6eabf1037 ("drivers/base/memory.c: cache memory blocks in xarray to accelerate lookup") Signed-off-by: Christophe JAILLET Acked-by: Michal Hocko Reviewed-by: David Hildenbrand Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Cc: Scott Cheloha Cc: Nathan Lynch Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- 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; } -- 2.35.1