Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1668917pxb; Thu, 16 Sep 2021 12:30:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/HaSXgdMEc4Ae1HE+ThoeY/eVus4FQZ+cyifRyADS59+Es88ZaB+0bhCZ0xnyg9KI+Cnb X-Received: by 2002:a17:906:49d0:: with SMTP id w16mr7800287ejv.455.1631820633879; Thu, 16 Sep 2021 12:30:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631820633; cv=none; d=google.com; s=arc-20160816; b=iAcIU+jmCL1XOjDQBQwYfTiOKHH6dT7jpajiQsY3sxGpM2abRPhDFPgI28HSrG9Y93 AIO5cQqjmB9Thev47JGzuqPOiESaqNYaqcmoSHVsJzqdnbzmZr4G/cvibgF9qR/QqZe4 ux6HmNdbKPVV+CBnoMNbL8m5VX76Pbdozj2Ij4FgKQVNjr/oZr7HJecoHn+MhET5fFlu EXEUV711xjtUsIMkgkz4QjYSsl64PBrQYHJJ0TWFl10y8PoUAaF8VKRySEmr3DcaO9zT RcYEp/ty3bHTHn/PGtAeMjR+NGrBDxtF/yeVsbSi3P+gYpa94MqxD3J35kXCRW+bO5BC nsdQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=j+W6XeDWsAagnUWJCSgLEEd+R3mbceg+HlWyCfMrKH8=; b=dra0MSyETFW4VJCcclza9FbD5MUKx6IaCIRVWbh+D5ouYD+oJ6GULp4RPpSdG3A4ZA fyRm51wUik81t5fvePHGuEPlvD8KrJuS3O/xewwWixBb7QgeZi9lG3Xn2YCcpE1Rhr5q vtW7D58zKs+idsH+vsvjZVfxhgEaGWHWgakro0vjMaPe8J7qVSHilqsufnAiCLoGk35d pu8qzr82ORO474A8xrwqFjeeQKkBtuszu3ZF7B4QvpO5fL52hqOJXhopuPpAaufrq+eT dEMC5p7eScPBDv0OUzQDpreNkb6TPf3SZAwdiSaAdEYLOVHhnfGQW5NpHjzNAvRjmL/Q krPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bMvQS+Q2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r5si4639922edy.450.2021.09.16.12.30.07; Thu, 16 Sep 2021 12:30:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bMvQS+Q2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S233564AbhIPQIk (ORCPT + 99 others); Thu, 16 Sep 2021 12:08:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:45294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232342AbhIPQGq (ORCPT ); Thu, 16 Sep 2021 12:06:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DF9EA61246; Thu, 16 Sep 2021 16:05:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808326; bh=tMRUhg+5IP7iS3QDrQIfnJwdTixPGUXbFkAY1SQ5LYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bMvQS+Q2visxE9XqCbeod1gLxV4CqoJ1pWlyu/RLxot7xn32brOjaddtZmL8Gp7Z1 Vj4X7CpC2q40QD3M6HFjclTf2MG8U6Ov+CyH3uaMTCphGwBGHanC2+ZVSkeESbzdbr 8ZbALFZ8fD6xkwiQOvSwiMLCV77JUqH6JG7xwCQQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Bjorn Helgaas Subject: [PATCH 5.10 048/306] PCI: Return ~0 data on pciconfig_read() CAP_SYS_ADMIN failure Date: Thu, 16 Sep 2021 17:56:33 +0200 Message-Id: <20210916155755.586019992@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Krzysztof Wilczyński commit a8bd29bd49c4156ea0ec5a97812333e2aeef44e7 upstream. The pciconfig_read() syscall reads PCI configuration space using hardware-dependent config accessors. If the read fails on PCI, most accessors don't return an error; they pretend the read was successful and got ~0 data from the device, so the syscall returns success with ~0 data in the buffer. When the accessor does return an error, pciconfig_read() normally fills the user's buffer with ~0 and returns an error in errno. But after e4585da22ad0 ("pci syscall.c: Switch to refcounting API"), we don't fill the buffer with ~0 for the EPERM "user lacks CAP_SYS_ADMIN" error. Userspace may rely on the ~0 data to detect errors, but after e4585da22ad0, that would not detect CAP_SYS_ADMIN errors. Restore the original behaviour of filling the buffer with ~0 when the CAP_SYS_ADMIN check fails. [bhelgaas: commit log, fold in Nathan's fix https://lore.kernel.org/r/20210803200836.500658-1-nathan@kernel.org] Fixes: e4585da22ad0 ("pci syscall.c: Switch to refcounting API") Link: https://lore.kernel.org/r/20210729233755.1509616-1-kw@linux.com Signed-off-by: Krzysztof Wilczyński Signed-off-by: Bjorn Helgaas Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/pci/syscall.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/pci/syscall.c +++ b/drivers/pci/syscall.c @@ -22,8 +22,10 @@ SYSCALL_DEFINE5(pciconfig_read, unsigned long err; int cfg_ret; + err = -EPERM; + dev = NULL; if (!capable(CAP_SYS_ADMIN)) - return -EPERM; + goto error; err = -ENODEV; dev = pci_get_domain_bus_and_slot(0, bus, dfn);