From patchwork Mon Sep 11 07:45:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 9946759 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EAF2E602C9 for ; Mon, 11 Sep 2017 07:46:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF24728B4C for ; Mon, 11 Sep 2017 07:46:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D410228B4F; Mon, 11 Sep 2017 07:46:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CB4128B4C for ; Mon, 11 Sep 2017 07:46:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750944AbdIKHqc (ORCPT ); Mon, 11 Sep 2017 03:46:32 -0400 Received: from mx2.suse.de ([195.135.220.15]:47686 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751071AbdIKHpu (ORCPT ); Mon, 11 Sep 2017 03:45:50 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C3659ABDC; Mon, 11 Sep 2017 07:45:48 +0000 (UTC) From: Nicolai Stange To: Bjorn Helgaas , Greg Kroah-Hartman Cc: Adrian Salido , Sasha Levin , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Nicolai Stange Subject: [PATCH 2/3] PCI: don't use snprintf() in driver_override_show() Date: Mon, 11 Sep 2017 09:45:41 +0200 Message-Id: <20170911074542.16777-3-nstange@suse.de> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170911074542.16777-1-nstange@suse.de> References: <20170911074542.16777-1-nstange@suse.de> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Quote from Documentation/filesystems/sysfs.txt: show() must not use snprintf() when formatting the value to be returned to user space. If you can guarantee that an overflow will never happen you can use sprintf() otherwise you must use scnprintf(). Commit 4efe874aace5 ("PCI: Don't read past the end of sysfs "driver_override" buffer") introduced such a snprintf() usage from driver_override_show() while at the same time tweaking driver_override_store() such that the write buffer can't ever get overflowed. Reasoning: Since aforementioned commit, driver_override_store() only accepts to be written buffers less than PAGE_SIZE - 1 in size. The then kstrndup()'ed driver_override string will be at most PAGE_SIZE - 1 in length, including the trailing '\0'. After the addition of a '\n' in driver_override_show(), the result won't exceed PAGE_SIZE characters in length, again including the trailing '\0'. Hence, snprintf(buf, PAGE_SIZE, ...) and sprintf(buf, ...) are equivalent at this point. Replace the former by the latter in order to adhere to the rules in Documentation/filesystems/sysfs.txt. This is a style fix only and there's no change in functionality. Signed-off-by: Nicolai Stange Acked-by: Greg Kroah-Hartman --- drivers/pci/pci-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 8e075ea2743e..43f7fbede448 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -722,7 +722,7 @@ static ssize_t driver_override_show(struct device *dev, ssize_t len; device_lock(dev); - len = snprintf(buf, PAGE_SIZE, "%s\n", pdev->driver_override); + len = sprintf(buf, "%s\n", pdev->driver_override); device_unlock(dev); return len; }