Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1001681rwe; Thu, 1 Sep 2022 10:48:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR5V7DxWjIW4EgjpUXmjvn0HtUj7untAis/1DScdutL2MG6xmPuqy18m9kFW6WTcPDc0SYza X-Received: by 2002:a05:6402:27d3:b0:43e:5490:27ca with SMTP id c19-20020a05640227d300b0043e549027camr30540926ede.307.1662054522603; Thu, 01 Sep 2022 10:48:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662054522; cv=none; d=google.com; s=arc-20160816; b=Lvvzp61fLgix6GwhrxelrMar2cdJ+kuCAGPXkLJ9joeBD1h2Ap9cZK9YjyEvNXCLu7 TzYHgkd6U/6sj8L1pqzkEO6pYruAERLLYN+7u7qwCj6PHT3cfDajFqE+aot3OQaEnZ2Y EkJbk+D504mBEdYjn6b02tMRNBAD6NkcFZ5TRd9VFjt2CrbM+RYF0OFdb+zPh4TBhf5h l8BXTJTohdzQtptps/x0YUMFU/BLGaCe4bu911NZ18D3qvm4E10VYiUTq+QZAFl5XuGF Sl6ShDQY9NLW8AxkdDnA9mi7vYL8Qhi1mmUPoSuy+dUYCDY+Uf2nvbJUr6DLKEZ36nLf opXA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=0x15QYOsq9/5WOG9TwMaEff/6w/MEiXY6/H45N9IBsc=; b=LUQT7p+tfddlWdzOzwRsslaTtatgt+HfYVBnXnGPBPeL51KxDEk7zaC9nbKCHoteh5 9JBVKATDpgT8nfvJ9lt5aD1JAu/otWlgcWh7ga/7Q2enPDv/38ItGFjpC35yE5OkII60 c406w99iF7Nkk5rFhrF2MKtFeyeQIXS2zEUiwpv5mBbSu6JXxCo3LAm1E5tyTGJHwARQ lTIDFlYfLIaBmHDi+XR1JMia95IYXm3z+HztaYMTbI29PmhxF+z7Lm4rwrULXqCphnpM vCqHSx/LwCuf9xqU7xB7xGO+/Y3VQeW4O6J8JuwsYG6+/5l7cog7zu2iDvj/hKWpU5Uf gO7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=H8f0YMRb; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cz18-20020a0564021cb200b004477b656f49si1706217edb.455.2022.09.01.10.48.16; Thu, 01 Sep 2022 10:48:42 -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=@linuxfoundation.org header.s=korg header.b=H8f0YMRb; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234555AbiIAQho (ORCPT + 99 others); Thu, 1 Sep 2022 12:37:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234515AbiIAQhm (ORCPT ); Thu, 1 Sep 2022 12:37:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0C4540548 for ; Thu, 1 Sep 2022 09:37:41 -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 744EDB82844 for ; Thu, 1 Sep 2022 16:37:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC0E5C433D6; Thu, 1 Sep 2022 16:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662050259; bh=hWmDmJING+9T7zsOMq3dR3oSc/Vy0IQXWEe0ccIh/Qo=; h=From:To:Cc:Subject:Date:From; b=H8f0YMRbKKllSmbL37gE5CRYwQZIa8a8p7m39evOGWW8Lfw3XgpvWh244aHY4kCJI nYbSgU7YqDquEtLmJzon3c8LIwX1SzRpSMET3ugAjbN/adOPczlMzBsrv6ffz8BINW CJ5tTqtqF+y4E/DJbtSdNz9uzuwucfMjQrHmr+EI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Stephen Hemminger , Krzysztof Kozlowski , Bjorn Helgaas , "Rafael J. Wysocki" , Andy Shevchenko , stable , Huisong Li Subject: [PATCH] driver core: fix driver_set_override() issue with empty strings Date: Thu, 1 Sep 2022 18:37:34 +0200 Message-Id: <20220901163734.3583106-1-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1582; i=gregkh@linuxfoundation.org; h=from:subject; bh=hWmDmJING+9T7zsOMq3dR3oSc/Vy0IQXWEe0ccIh/Qo=; b=owGbwMvMwCRo6H6F97bub03G02pJDMkC908fXrFiPmubv/fh6GnSxSc0g4zZ/6S2NnbreVtxx5/+ blTYEcvCIMjEICumyPJlG8/R/RWHFL0MbU/DzGFlAhnCwMUpABOx8mBYsHO16rwnr2v26zBfixN1Ot VYO4vrFsNcQalOP8ulr3MeP8pqujXTuEtpq6I3AA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 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. Reported-by: Stephen Hemminger 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 Tested-by: Huisong Li Signed-off-by: Greg Kroah-Hartman --- drivers/base/driver.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 15a75afe6b84..676b6275d5b5 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -63,6 +63,12 @@ int driver_set_override(struct device *dev, const char **override, if (len >= (PAGE_SIZE - 1)) return -EINVAL; + /* + * Compute the real length of the string in case userspace sends us a + * bunch of \0 characters like python likes to do. + */ + len = strlen(s); + if (!len) { /* Empty string passed - clear override */ device_lock(dev); -- 2.37.3