Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2319632pxb; Mon, 20 Sep 2021 18:42:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvTUv7Xcej7pts25rGv1tHXGjdHqJwJijqSrq/YN220dRLRFLEvHZ9jmBhX6Xl/1Zr5QWP X-Received: by 2002:a5d:8715:: with SMTP id u21mr21564368iom.1.1632188575904; Mon, 20 Sep 2021 18:42:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188575; cv=none; d=google.com; s=arc-20160816; b=L57o13goKHj4MLCyxLVnTxrxcAvZUmvY93qy9kQ8+cy4WnSFTmetmj0xV6idSluH26 vB9XdQrPegLlCr7JkOtPNSHi2Gg4D2r6kwPbtVDopwWcdRJWMCFV3Ug0fMbnJAHnOTLe GQjk/NZQyXReXUqajTeiwkbFFGXUtEOuZoncVvDqWmn8qqGrgy+Hqv/K/8OxxRnY/BH3 EFm9myiMC0g5oOVmb1M5J2YD7pV7KzRC6ypT8yn8dYlhkKDhzUSTI6a5kWXNixVxQ5LP rY0mm+XbjVH0gicSjQ7yCciMRXF0pZax8JRFaypp1FjN7wV0XUVmyYkdy/IFobYBut7Z e20Q== 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=8vbxUONxTNLKue8Wq2Ak93SZWNM81fVd2rQjcv73Jeo=; b=xQTug7xDIn0TFKN2I/tEOYDRRuKY+ieqPYJpg5IQK9MJSHNF0yTBhYvJYEYKL4kDCh lrR4O+uQ9SG1/eGYr3fyurL4sG/E/xQ2XBiW16s3GKvBZqA5PnOuh4avQcQ55tyxD165 TZih/VLajJsGZ30d4xbTV7gCx5KuMRuGcD0pWAKcxl3H8p6KRQ9irhoHqm3SKaflx8hT fKyWByQh9dpIVUI1lUxreZoFQpDoUJsY0T/lUjrgixRX0R1KvZWFQwEiS8AI8vM+yDw2 gWdTZpXDNRwyIvlO+bdVtdHx7iCdiHUOhlzgo/88IM0DZmt5fHEaXlXNrrC85kWUiIlJ TXUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TXamzRdW; 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 k17si17661544jav.64.2021.09.20.18.42.44; Mon, 20 Sep 2021 18:42:55 -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=TXamzRdW; 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 S244115AbhITQwJ (ORCPT + 99 others); Mon, 20 Sep 2021 12:52:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:38506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbhITQtg (ORCPT ); Mon, 20 Sep 2021 12:49:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AF63A61205; Mon, 20 Sep 2021 16:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156489; bh=zRGZnzWLC/tyW+CceMiMxIrQNdGN1bWoqL0AJ5tT+28=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TXamzRdWJp37/UFjHfGyq7vEyVRRAzeZahGAqQ9ISy7Lo68+MDLEEu9cLiG/Pt+1F /svJuKwikjpbGoBPoek684/5jd4kBNWEYJ/FPbZ3KIno9YB3Ub4kPbgsGvX+Xx44uW LC5JMXG6HE9SiyCrf7AZ6Vw/rAsUXLutFJ0m598k= 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 4.4 082/133] PCI: Return ~0 data on pciconfig_read() CAP_SYS_ADMIN failure Date: Mon, 20 Sep 2021 18:42:40 +0200 Message-Id: <20210920163915.324351822@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163912.603434365@linuxfoundation.org> References: <20210920163912.603434365@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 @@ -23,8 +23,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_bus_and_slot(bus, dfn);