Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1952933rwd; Wed, 17 May 2023 03:53:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7fPpy2PvdKc5CFtTfBd10q6Zc1MQd4PySnGNVFagU80kMHvgQzwHibZ16I0zS4KxFLQjug X-Received: by 2002:a17:903:1249:b0:1ab:220a:9068 with SMTP id u9-20020a170903124900b001ab220a9068mr53124861plh.42.1684320794716; Wed, 17 May 2023 03:53:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684320794; cv=none; d=google.com; s=arc-20160816; b=p7n6J0zyExh5D4YSsUeYVbxoEAnhMaVpdoCxZS7YvyKCY0A8z9AM1AXikcciqI/yyw 9LI4L32Oy2Q1DEDFqZihGR8LKBdRBB+fGpg54UcmHIOFEpDCJQ4wYx7NQQ8z3Q8w69rE DIZPwUZHad8lGXp/Gyw7/60W5GC/+KpgRMBxqiRJy9JMxlu1xllrMhQcKqoSk7CQn8h+ ysLEWYc/4ejZwdiDnn+HPT1h3I1F3LhFuW0hpd1KmDllAiOZdDdPLVmG5KEPCo16NksH nDF1+Wc7kPpyTFgTFKCBpC/Sww8NBDkiy6uFMeyTudBiEuctFEWQvOlzowiDi+VqQpx/ dqIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=9P//FAyrLI49zVRWd6x4csvjhmE7MGcscwvJRywAf/0=; b=M+hkAPSY+8AAtMk/c5iiOeEgIjfZwN16QN+IZn+MWMLxAe0GTqcKvsQYaH7/IYc2kC muOfL2x5anazThmrkwCxaFRas4z85cx+O8VxUsMSo8HEux8vtpTUYf08zbdblVy92Kcu t7NM4KjWwWzN7/Gl4qI0K36+WX5UoUGBWob2yCpUJE+6CVH2T6PhdupQj4wDP9FkIex6 XEIr0F8PfAkvgJTImc5l3cPQO3mlfLG/CCp7SidAoeT7f4p+xd9oF5d8U+/P/B7EU7g3 Hwji4zqQsFE+iY4QroYgfdOydNKHI/yjcEixm8caRJ5wjFbZEvUFNt7l8NQDAK4OMhhv PwEQ== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x11-20020a17090a8a8b00b00250db0f5689si1433190pjn.179.2023.05.17.03.53.02; Wed, 17 May 2023 03:53:14 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230430AbjEQKmM convert rfc822-to-8bit (ORCPT + 99 others); Wed, 17 May 2023 06:42:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229921AbjEQKmJ (ORCPT ); Wed, 17 May 2023 06:42:09 -0400 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6459D420B; Wed, 17 May 2023 03:41:52 -0700 (PDT) Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-94a342f4c8eso13719866b.0; Wed, 17 May 2023 03:41:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684320111; x=1686912111; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cnrYckLOMdeQP/cDiOa38SdJDj0LdQRatYnbgv9Ep9A=; b=hSlDZfxrVyV8JDvFe1ZdZm2NT2WU+K2lvAFWXVBuxvrPzV/94cPu79Ab8Q6PYoqOta OhYpQqqztzz080gQhCkfQtEJ+yn6jDU/17B9BLMe5IeyVVke8ViJok8MsaOOkNYg+y2S ip8btiob7Lq1xRA5GmQDR5agjaTCwNSugY6p5CW9zAL3OGlWrjjAMj6iunR5rWkpBPse Rrl/Z+vxJKPKLuAm6F0xmnmIsmeeCjBl8GRQWLybuY4VOybNMG4y+cEXSIWToEfvvfkI f1heZtOUwgLBSEFj9T/SMGhVyM8R1tLi2Ei+rDdB5kWw6eWpXxt+UsPFBK/GoBx0ZG2i BrbA== X-Gm-Message-State: AC+VfDxK633w+VW1ruENsy1YvXCVkKtCNzIxt6PCGaZ8T2xFjqUMgOLc kLdd2X0Z06SS959uR78PAmwswaezR3QZj6gkYXo= X-Received: by 2002:a17:906:51c4:b0:965:c518:4681 with SMTP id v4-20020a17090651c400b00965c5184681mr1637401ejk.7.1684320110524; Wed, 17 May 2023 03:41:50 -0700 (PDT) MIME-Version: 1.0 References: <2023051610-stove-condense-9a77@gregkh> In-Reply-To: <2023051610-stove-condense-9a77@gregkh> From: "Rafael J. Wysocki" Date: Wed, 17 May 2023 12:41:38 +0200 Message-ID: Subject: Re: [PATCH] driver core: class: properly reference count class_dev_iter() To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, syzbot+e7afd76ad060fa0d2605@syzkaller.appspotmail.com, Mirsad Goran Todorovac , "Rafael J. Wysocki" , Alan Stern Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 Tue, May 16, 2023 at 9:20 PM 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 Acked-by: Rafael J. Wysocki > --- > 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); > -- > 2.40.1 >