Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1548326pxb; Thu, 16 Sep 2021 09:41:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxm7ro7MJJt3XdBqMU+eyioVGGy6US8AIvKnIUIJ9LUpjBARMxaj2oXbHo0lXr5r+q65PSQ X-Received: by 2002:a17:907:16ab:: with SMTP id hc43mr7214629ejc.195.1631810467817; Thu, 16 Sep 2021 09:41:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631810467; cv=none; d=google.com; s=arc-20160816; b=iEgt17qNgIbBqeGx9QsH78NgUGotjq6owxVpS96YF5nRmniqj8bRZYBOOZIMkpdqaM OKqtpMjtAAqiShWs/Dp3SSXStkyIhNpFMcGqSpm+h1Yj2A6PnJJYOzQK4IfbxIqhRuZG PZ0mAmCNuMqEykyIVAbnBIRVuaDf9ykTRHC/adpdYkbzqVRg9aUpnAnDDVm9FPQjGhdM d4LdoNd7HQeBU2b4rxkwFrtLZBRcKGNVAGShDbv9wU2tqBxR8pCEHyKWA8dYH2VMc8t4 vf0HzIQUt6DTffVYaVpGWcgRv3sij6l1TSE/um8FJpSWL7fJkzzawNSU7zBfGiagazTz GG6w== 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=NwsDSKATvtxan/xagh4kO0QH5XDngh6ZXgvkkBMDDrd5xF5w0WXFuQiw06xZ4bhunO Lp2s2NAbKPSvASnH3I5fnTgnE2lSj3izKerdCnZQu9xEx78loYliwuJ90MpW3QXdlxYR 0mTyuNkiUyb1nrAV3yBpzBzbLUPt9rbO8QVL4ThvA/cOQmTh0XjUo6HixWY775gEpwu9 0APEK8cqUdtQ4BSU6gi6oxX4229UpVY/OOUOgCg3QWsINCHWuhdErMTT/kZAHmuW5syB wqFfB3D/rUDWutbC4lH4mz4Og6ZKAQJxNsI54mGnFu6hQir4NZp4WFk19w5ZIJrFR48X T5Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QjP3ovax; 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 p17si4244238edy.229.2021.09.16.09.40.42; Thu, 16 Sep 2021 09:41:07 -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=QjP3ovax; 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 S244573AbhIPQjT (ORCPT + 99 others); Thu, 16 Sep 2021 12:39:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:44986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242296AbhIPQbr (ORCPT ); Thu, 16 Sep 2021 12:31:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B62F061884; Thu, 16 Sep 2021 16:19:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631809187; bh=tMRUhg+5IP7iS3QDrQIfnJwdTixPGUXbFkAY1SQ5LYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QjP3ovaxDmjMRHCEc4+pJskzNmqjHQEn+jEWMR4J4vQsV1jVjfFlZ4f1EseBVScTU 6JJG0vC9Vlx7JCfRyKEoTSv9A9Cpflq4o3e6I84ig0cbQHOpxLnu5W3JUXt0o1t0Vh AIqQPgWVSOkh/6cdb8p7iXyCypQwgLALi0yZ+ABM= 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.13 062/380] PCI: Return ~0 data on pciconfig_read() CAP_SYS_ADMIN failure Date: Thu, 16 Sep 2021 17:56:59 +0200 Message-Id: <20210916155806.102726781@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155803.966362085@linuxfoundation.org> References: <20210916155803.966362085@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);