Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1531098rwd; Thu, 18 May 2023 13:21:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5P6QpkwfjmORYSayv5AqPDk8/72/qNC/e9dA4+fJGCdGQUM8h7B2mWU8Nxay/+7ZE2VQFA X-Received: by 2002:a05:6a21:3810:b0:109:a30a:92b5 with SMTP id yi16-20020a056a21381000b00109a30a92b5mr887613pzb.27.1684441261486; Thu, 18 May 2023 13:21:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684441261; cv=none; d=google.com; s=arc-20160816; b=elMr8kJAX7LyOYGv/xK+31GmjCBAVQGjnlujLoa6/SqICkznUGSaBpG64mGNPJK3cB dJinV6zVeGjX/rHIf22dlGvic4yF3QagaIfMsBBsWosbPfbXn/QlprjAdWhHC2Wt0lIK gipdSZKogULvCObOWlVNen1y8N/OmUUgBTaxtHhVPciU9D3Aml9yeYapWhxrokpc048n yeHgw/aztUEsatKOgfV6bBKWpvZc6wVZ7RVQzq75vp2rfOHWvLABrlr4FFuZ6MQxiWhg kYTvG3APAxnHL1SDukAjLOqPPJ4UPdValxpiRo9/VJOJprVczmRLgz6y9dqGKv3aEnIc h37A== 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:dkim-signature; bh=lb25iAGnMcfHIhBSkBTP0q61s1mMicvCMmYgR1PnWVY=; b=HvOetZFNRUALKuD9i7yhuzqYJG5Hg355qR7kdNjfRjZDfZQAtWYr+lX35Mi6o/J7ER upwWHfflKUKhX2ds+VPJTMC5cLMYDXDHmXyiStf0Se5zNf8nVSsXo4oaPcwOyVq5Mjn3 bdiFA3QAt2AnFgHeprrp+pS48mibM6+S+4F7vRd7WkbIlJRugASOlgsZElJKNtbuKtws eujqYwEU/IQvaXbGCt9b/SGN9gTp3BVEZY32nhHqIVNk2uQdAilarPzwYz11oK+nM66r 1jJ0wYfEoHnuqAgosQIyV+R4gZ6VsjWwnKMVobZLOg0cnNe3dBL1Iiiydpqpo3md+CHS G3kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=ULkr652d; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=EGTcjHmI; 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=alu.unizg.hr Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l70-20020a639149000000b005139e8ca7b1si332626pge.494.2023.05.18.13.20.48; Thu, 18 May 2023 13:21:01 -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=fail header.i=@alu.unizg.hr header.s=mail header.b=ULkr652d; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=EGTcjHmI; 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=alu.unizg.hr Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230242AbjERTme (ORCPT + 99 others); Thu, 18 May 2023 15:42:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230031AbjERTmd (ORCPT ); Thu, 18 May 2023 15:42:33 -0400 Received: from domac.alu.hr (domac.alu.unizg.hr [161.53.235.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ED79E6D; Thu, 18 May 2023 12:42:30 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by domac.alu.hr (Postfix) with ESMTP id 51F9E6018D; Thu, 18 May 2023 21:42:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1684438948; bh=8TuUr/tbhWxw/Wl+c1CUiJnNsg4NRh0wA3s+nfMW4/0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ULkr652diD3aZMEl8lIMDS5dVWGd0asdy7dR+2X7PL5Qonso9mzYF+yprshQCNiGq X98B2Jo8FKpyKP3lu2F6CPzJtC5ilcZX+fz1Z0A57CQEC/JeUIAasCdb38AF0AkqTb H/kNQHegJs+EZ/Bmy4WO8Hzz+vgHRzt2Q289h/ip4PXUMG0YdQ2V33Ram1bsT2CAgS CP8iFXJ5hGzNUDiydEx2CR4+VGlq+/GqxrZA1oIZy4qgiuBpTsm11h19Urv/369tKv mYeYfMaLzwwfvWH18d6OlEOw9els5HJPvpJ5t7PRo9s5ZSXAlg5lLkJmsP8069t5eH KGDna0oltbX7Q== X-Virus-Scanned: Debian amavisd-new at domac.alu.hr Received: from domac.alu.hr ([127.0.0.1]) by localhost (domac.alu.hr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tzS0IgwIkEhc; Thu, 18 May 2023 21:42:25 +0200 (CEST) Received: from [192.168.1.6] (unknown [77.237.113.62]) by domac.alu.hr (Postfix) with ESMTPSA id EDFA760189; Thu, 18 May 2023 21:42:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1684438945; bh=8TuUr/tbhWxw/Wl+c1CUiJnNsg4NRh0wA3s+nfMW4/0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=EGTcjHmIDggZ8hor6P64XQL/UpBQoNU9/LBm/5CrxLwXPmQXQhS8rKlO2TseY/GDF AY7u7syczZeCtxmS94m6DLjB17y5QUeZfucAvgyCasxw4yH7hF/m6b9xvuYHHjBmPx C8LBSQ6FAYruE6sR4x5TIqmRyf8dAaqJU7vt749tGtMlGC1+rLomkj0UGqadAn3qxS KbZUR3/b+/d0zL9T/rf1d8dmlNp3lywYsQJ4jPna1+VAht61NIIntoEzXCmPx787VU ui5YPEosZF0dfGwYF/wOOwQ/lMHadnOLQqEEuRv99Aijl/3g3YUMEFaXd/K9Ns1N6i gxKbdKctE6bbw== Message-ID: Date: Thu, 18 May 2023 21:42:10 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH] driver core: class: properly reference count class_dev_iter() Content-Language: en-US To: Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: linux-usb@vger.kernel.org, syzbot+e7afd76ad060fa0d2605@syzkaller.appspotmail.com, "Rafael J. Wysocki" , Alan Stern References: <2023051610-stove-condense-9a77@gregkh> From: Mirsad Goran Todorovac In-Reply-To: <2023051610-stove-condense-9a77@gregkh> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 5/16/23 21:20, Greg Kroah-Hartman wrote: > When class_dev_iter is initialized, the reference count for the subsys > private structure is incremented, but never decremented, causing a > memory leak over time. To resolve this, save off a pointer to the > internal structure into the class_dev_iter structure and then when the > iterator is finished, drop the reference count. > > Reported-and-tested-by: syzbot+e7afd76ad060fa0d2605@syzkaller.appspotmail.com > Reported-by: Mirsad Goran Todorovac > Cc: "Rafael J. Wysocki" > Cc: Alan Stern > Signed-off-by: Greg Kroah-Hartman Hi, Greg, Did I forget to give the Tested-by: Mirsad Goran Todorovac I apologise if I did. Best regards, Mirsad > --- > drivers/base/class.c | 2 ++ > include/linux/device/class.h | 1 + > 2 files changed, 3 insertions(+) > > diff --git a/drivers/base/class.c b/drivers/base/class.c > index ac1808d1a2e8..05d9df90f621 100644 > --- a/drivers/base/class.c > +++ b/drivers/base/class.c > @@ -320,6 +320,7 @@ void class_dev_iter_init(struct class_dev_iter *iter, const struct class *class, > start_knode = &start->p->knode_class; > klist_iter_init_node(&sp->klist_devices, &iter->ki, start_knode); > iter->type = type; > + iter->sp = sp; > } > EXPORT_SYMBOL_GPL(class_dev_iter_init); > > @@ -361,6 +362,7 @@ EXPORT_SYMBOL_GPL(class_dev_iter_next); > void class_dev_iter_exit(struct class_dev_iter *iter) > { > klist_iter_exit(&iter->ki); > + subsys_put(iter->sp); > } > EXPORT_SYMBOL_GPL(class_dev_iter_exit); > > diff --git a/include/linux/device/class.h b/include/linux/device/class.h > index 9deeaeb457bb..abf3d3bfb6fe 100644 > --- a/include/linux/device/class.h > +++ b/include/linux/device/class.h > @@ -74,6 +74,7 @@ struct class { > struct class_dev_iter { > struct klist_iter ki; > const struct device_type *type; > + struct subsys_private *sp; > }; > > int __must_check class_register(const struct class *class);