From patchwork Thu Jul 29 23:37:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12410101 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 030A1C4338F for ; Thu, 29 Jul 2021 23:38:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D60D060F23 for ; Thu, 29 Jul 2021 23:38:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234878AbhG2XiI (ORCPT ); Thu, 29 Jul 2021 19:38:08 -0400 Received: from mail-pj1-f52.google.com ([209.85.216.52]:44548 "EHLO mail-pj1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234448AbhG2XiI (ORCPT ); Thu, 29 Jul 2021 19:38:08 -0400 Received: by mail-pj1-f52.google.com with SMTP id e2-20020a17090a4a02b029016f3020d867so11865407pjh.3 for ; Thu, 29 Jul 2021 16:38:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=czfwimJC2Qqp4h3gtTtuU27/KqvNQcct0k1X3sUzr98=; b=ra8ryIpVRssalTgFJ4bcFhknyJFH4xq0zte8PjdczG88zIVGOB5cpRm1/pnIouldXv 16JZcgKxYlLn9Li1LpQQkh5IptaDQwYFGnivDwBMod2d+IyCumE/81X5Du0nRVynQfc8 xwNZdSpVjtZw7j4D83lw2Y27QFkxCV8aB1Gk98FEUbzJq5S0RCMfYHkiFiVgwR5cBKkM /NZiA4kTvZGtoSdgpJaJfrTu6E+5Ey3jVcOKw/7OlXgmcee09oKxYLgPF8DWKIut4/FC ToMlZS5xB4rm5gyemW5ktQwiq06U1L5Huo2kTeu4soJ0uPhGqcjmOnr/DNYpONr9VG9w 45Tw== X-Gm-Message-State: AOAM530J76rQ+gWntBM9e4YceS0H+ANXhiXP1GaZw3w9qXdqSBv5rK1e MtB/QuifG7NLriBUNgFBV+k= X-Google-Smtp-Source: ABdhPJz4yiIOVkIYZnkbqNlwMkqKXGIFFWfEbx0jJ9PuHPRVN9Wt9G+gDgPY66UerK9tlM7tpWlu9w== X-Received: by 2002:a63:1053:: with SMTP id 19mr1935963pgq.395.1627601883437; Thu, 29 Jul 2021 16:38:03 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id k4sm4446831pjs.55.2021.07.29.16.38.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jul 2021 16:38:03 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org Subject: [PATCH 1/2] PCI: syscall: Set the ~0 value on access failure Date: Thu, 29 Jul 2021 23:37:54 +0000 Message-Id: <20210729233755.1509616-1-kw@linux.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The pciconfig_read syscall has a special provision to handle users that don't check the return value for a possible error code and rely solely on checking for the value of ~0 to be set as a result of the PCI configuration read failure. The commit e4585da22ad0 ("pci syscall.c: Switch to refcounting API") changed this semantic of setting the results to the value of ~0 to indicate read error concerning CAP_SYS_ADMIN capability flag validation. After this commit, the syscall would simply return -EPERM early should the user does not have the required permissions. This changes the original behaviour which might not be something that the users of this syscall expect, especially since some of the problematic users do not check the return code whatsoever. Thus, restore the original behaviour of setting the results to a value of ~0 on read failure to include the capabilities check. Fixes: e4585da22ad0 ("pci syscall.c: Switch to refcounting API") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/syscall.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pci/syscall.c b/drivers/pci/syscall.c index 8b003c890b87..b842af1e06b8 100644 --- a/drivers/pci/syscall.c +++ b/drivers/pci/syscall.c @@ -22,8 +22,9 @@ SYSCALL_DEFINE5(pciconfig_read, unsigned long, bus, unsigned long, dfn, long err; int cfg_ret; + err = -EPERM; if (!capable(CAP_SYS_ADMIN)) - return -EPERM; + goto error; err = -ENODEV; dev = pci_get_domain_bus_and_slot(0, bus, dfn); From patchwork Thu Jul 29 23:37:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12410103 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FBF5C4338F for ; Thu, 29 Jul 2021 23:38:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E518460EBB for ; Thu, 29 Jul 2021 23:38:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235254AbhG2XiK (ORCPT ); Thu, 29 Jul 2021 19:38:10 -0400 Received: from mail-pl1-f169.google.com ([209.85.214.169]:45866 "EHLO mail-pl1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234448AbhG2XiK (ORCPT ); Thu, 29 Jul 2021 19:38:10 -0400 Received: by mail-pl1-f169.google.com with SMTP id k1so8806013plt.12 for ; Thu, 29 Jul 2021 16:38:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Y/JkeTo435+LRPpnF2QQ8YSozs7CUc/A/f0oWhjMXgM=; b=mzk+m44NPgzjUjo8awFeMnr7UTCzkgvt3MOnTZAAedxCJTLOWMRLqA62FMSf7WpGQy pNIQ9LeMenAc35TXdOhLE/6EUFgQlcg2OuhnuKOuNUhvbqYDv9WikraULAHgA9w3Ij1q YTyqQ3ZSHUqkhYOImLsmipaMjGvknlodZrQsvIi1BB+Bwe5PXidsHJ5zpbU9kKlzcIsW jzD2723SMpGPocDW39mfxZZSBWJtAXrbHme6K3mSvEdMtq7lXtZOFuSmXvoxzCRpBP/I 3fvaqUuN6mWEsl0R4qbW80SwEhuZuqDRDnWhjBDY4YJPdlAHNtU597wGgM0aOIOmxAVH /YrQ== X-Gm-Message-State: AOAM533s8+9+QbPYXJGwIJ/L5EICGchY/mllLs2u6dfzwsLhB6siXHrh zFSZlK/cjFjwjZvPxBduOr8= X-Google-Smtp-Source: ABdhPJzZzutiYPljQVTbytPr5zrlPKiUvIkIlBDJR0S/W3LI0UZd8jD1koy/Hh49F8oOiXbWfgNyxw== X-Received: by 2002:a17:90a:6a0e:: with SMTP id t14mr7906143pjj.19.1627601886585; Thu, 29 Jul 2021 16:38:06 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id k4sm4446831pjs.55.2021.07.29.16.38.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jul 2021 16:38:06 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org Subject: [PATCH 2/2] PCI: syscall: Change type of err variable from long to int Date: Thu, 29 Jul 2021 23:37:55 +0000 Message-Id: <20210729233755.1509616-2-kw@linux.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210729233755.1509616-1-kw@linux.com> References: <20210729233755.1509616-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The pciconfig_read syscall uses an err variable is currently declared as long and even though it matches the function signature as generated by the SYSCALL_DEFINEx() macro is a bit wasteful as the syscall returns a handful of simple error codes. Thus, change the err value type from long to int to lower the storage requirements and also align it with the pciconfig_write syscall. Related: commit ef9e4005cbaf ("PCI: Align checking of syscall user config accessors") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/syscall.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/pci/syscall.c b/drivers/pci/syscall.c index b842af1e06b8..525f16caed1d 100644 --- a/drivers/pci/syscall.c +++ b/drivers/pci/syscall.c @@ -19,8 +19,7 @@ SYSCALL_DEFINE5(pciconfig_read, unsigned long, bus, unsigned long, dfn, u8 byte; u16 word; u32 dword; - long err; - int cfg_ret; + int err, cfg_ret; err = -EPERM; if (!capable(CAP_SYS_ADMIN))