Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2565643lkm; Mon, 20 Sep 2021 18:52:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3EVbbg4he+CCrMCL34YA5C3pl9TQUZiXKCK2/sU/7tmhhR9vJIoWqQjK3iCF4H0KRQXEq X-Received: by 2002:a92:cbc2:: with SMTP id s2mr19098173ilq.228.1632189037635; Mon, 20 Sep 2021 18:50:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189037; cv=none; d=google.com; s=arc-20160816; b=ESA4a/NvVE9J2o4aa8HUAf6dVxpK6d7L/Y4VJcJmrTtkPzTdnZCeHXxbS0zbCjveL6 EJLM74/RCT9z1hrPzfHmUiqHfcdILjxAqAQvyU/ZgpkV0Tej+kAXTATHFZ5W2FwC0vi/ en9d6qgnlsqhM+yjOsj2lMaYGB4rKD9zdlh90JQiN+KVypcLh99Ia7YxTntDPDUqY2wP VM/XGycFBI7GWql+VR9OJd4XwYylBbkbWdxVUCKDrTyvmYrBrCEj8NZgH7nVKOGW3J55 T7dJykB9iK4Lv7P5iuCMPwt7GKEj3DKSbA/OyVnlb3he8yyz5CselHUvIeWdjjmCIK8o FbXw== 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=ojktoJTtwYnFDDsRgG9zE86A+37K6eMRnZK4B0taxmHEXffqOxOO7HU+/A/Tizfjel kQvL+xK7Djn1GGF/gaB2fPJA6p1MYqO5M6npoxwtkfBtEVjQW66Kbii1mtLbegIQURH2 M4rRB41HFrFjmDDB2uoM9xP7KlJVlSNEZ/0FW0dfMLVMyukwryW4THLGFWLt1yvxs1d3 Ichli5HFlZYK0q6cEB3Xq3DRkV5J4sxLbkP3t7sm9IYLEyGFz2hD/ZxOtc61TQf6Yx/4 RJR9iMcZ09FtNJR6IjjDkVm76NRlztBFY5tqelwcTc3TAfGInWr5iE8HW0meyTFeG24r P0TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UvBmvQ8y; 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 j15si13854857jac.8.2021.09.20.18.50.26; Mon, 20 Sep 2021 18:50:37 -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=UvBmvQ8y; 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 S1350766AbhITSHX (ORCPT + 99 others); Mon, 20 Sep 2021 14:07:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:57388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350878AbhITSBn (ORCPT ); Mon, 20 Sep 2021 14:01:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D6B90619EC; Mon, 20 Sep 2021 17:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158167; bh=tMRUhg+5IP7iS3QDrQIfnJwdTixPGUXbFkAY1SQ5LYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UvBmvQ8yMpOkYevnZGycvJQfeu1re7Mcwv1fRbdPlbWUgwtZ0MhBOwmpNI+w2Kh9c RJ830CyjtoxPaFogwexRShlql5BqytJ/B86mEswABJZCSBIjhe56iZUacdb5LuujUr C1NTy1kPFvA0vZsCZol5rGe+XrLeUbWMmNuY72qY= 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.4 031/260] PCI: Return ~0 data on pciconfig_read() CAP_SYS_ADMIN failure Date: Mon, 20 Sep 2021 18:40:49 +0200 Message-Id: <20210920163932.178528111@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@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);