From nobody Fri Dec 19 07:49:09 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDC8CC6FA82 for ; Tue, 13 Sep 2022 14:13:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232590AbiIMON5 (ORCPT ); Tue, 13 Sep 2022 10:13:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232705AbiIMOM6 (ORCPT ); Tue, 13 Sep 2022 10:12:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC0565AA2C; Tue, 13 Sep 2022 07:10:11 -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 ams.source.kernel.org (Postfix) with ESMTPS id 1DBFAB80EFC; Tue, 13 Sep 2022 14:10:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B83CC433C1; Tue, 13 Sep 2022 14:10:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078206; bh=MUCm6y82PpyUWpOBizM5CO4R92B4DSw/MWs73QLkUos=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L91An4fUmaaZ6PTlBAU5dpblcINi/OgUl9a1A2msBAuJZ6RHEj//tp2lFWlRzcyqr j9ZzAjYeSpQbzV1DZhAIFdDUjE6QHGdokd3qk/GNOeYApEhwwmD4BVrpVOiYD4lPpU 2Ss8IV+CwVNREKiOfcQHRzCkzd6kRYNcpNFdradg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Krzysztof Kozlowski , Bjorn Helgaas , "Rafael J. Wysocki" , Andy Shevchenko , stable , Stephen Hemminger , Huisong Li Subject: [PATCH 5.19 053/192] driver core: fix driver_set_override() issue with empty strings Date: Tue, 13 Sep 2022 16:02:39 +0200 Message-Id: <20220913140412.581153564@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140410.043243217@linuxfoundation.org> References: <20220913140410.043243217@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Greg Kroah-Hartman commit 5666a274a6d54372d6b79b1f78682a9d827e679e upstream. Python likes to send an empty string for some sysfs files, including the driver_override field. When commit 23d99baf9d72 ("PCI: Use driver_set_override() instead of open-coding") moved the PCI core to use the driver core function instead of hand-rolling their own handler, this showed up as a regression from some userspace tools, like DPDK. Fix this up by actually looking at the length of the string first instead of trusting that userspace got it correct. Fixes: 23d99baf9d72 ("PCI: Use driver_set_override() instead of open-coding= ") Cc: Krzysztof Kozlowski Cc: Bjorn Helgaas Cc: "Rafael J. Wysocki" Cc: Andy Shevchenko Cc: stable Reported-by: Stephen Hemminger Tested-by: Huisong Li Reviewed-by: Stephen Hemminger Reviewed-by: Krzysztof Kozlowski Link: https://lore.kernel.org/r/20220901163734.3583106-1-gregkh@linuxfounda= tion.org Signed-off-by: Greg Kroah-Hartman --- drivers/base/driver.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -63,6 +63,12 @@ int driver_set_override(struct device *d if (len >=3D (PAGE_SIZE - 1)) return -EINVAL; =20 + /* + * Compute the real length of the string in case userspace sends us a + * bunch of \0 characters like python likes to do. + */ + len =3D strlen(s); + if (!len) { /* Empty string passed - clear override */ device_lock(dev);