Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2566996lkm; Mon, 20 Sep 2021 18:54:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/rqZRQMi9ng8tv2AF6z2sBlzOCY614n+CDCstcsIpVeOFaPkzpwl+x5VRWH0dXyyvkKKo X-Received: by 2002:a92:cd8c:: with SMTP id r12mr12430885ilb.164.1632188943100; Mon, 20 Sep 2021 18:49:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188943; cv=none; d=google.com; s=arc-20160816; b=Y8lGQfNFHabtai2EtD3KdRQb4DJ1FtqhoKqlXEzK+sWVUesf4k+AZcV8rFYs0iJF4h 6pPcngpUkS2W/OtQJpSCVt7vsjBaovoUpJTH9UTkKA0Lnybx5yfbmT9grao6Sktdvzl2 ik5sZcDwEHTW6RHOp3oUWX6IE/eamKQVO1K4vPqHofquwt22/N0+7zRTP79M5nJyO0Od BgRoo9F4V+K3ae/Ag537//6ezUsKEBiCHElm2rmOXloIQOO6jfIidkfZjaj7Ch5aYoge PfHdcagohfl3XMbSTzJWMOwe1+n5vawZLRf+XSSNqvJMBvn94XlL9z7YdnjqqTn4aCO7 bAMQ== 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=hImFXDUfqSbEIggwRlnLgr+813SPLFsqFA6/EGNGKDw=; b=JISyHMB+PUrkxZko0whtNsAvpdIwp1guL3ZgdWOl3+STy3KiTj/0fYXWit4QQ2mizv 5rNbtbFb1Q4uDIbOcIkzT8rX/lrEnAFJ1yZ8phXk+UbTQbTC34kLYxBufcDp6UX3v/Jq j/IlKe9Q4DDULaGHbaAbNKlhU7VwY01Vw21gJblbbmJ95tIjlDDx4w0hY/0vzd8xKlT8 yqS3aK9/yQejTxNc64pix0GKdX7OP09KDAxSB1WET3lp0+/WbCK+U3GlLLkmyr+/uQn/ Jk8qKB1aiBXTe4X+t87/IczuGu0eW1AUIBae52uO2vMmxWrUFlqfoqEJvruiqV6bgTkP zJCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RyEbSRdM; 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 j11si2690790ils.94.2021.09.20.18.48.46; Mon, 20 Sep 2021 18:49:03 -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=RyEbSRdM; 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 S1349129AbhITRr3 (ORCPT + 99 others); Mon, 20 Sep 2021 13:47:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:48100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353496AbhITRow (ORCPT ); Mon, 20 Sep 2021 13:44:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4BDA261B7B; Mon, 20 Sep 2021 17:09:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157789; bh=42jQpy0bbH+YwaC6FFk1nb8v7qSXfmvXdLKUpShAfGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RyEbSRdMboWV5Mik6zvMaOapBDQvswhms05LjExp+0XMqxvivkyPFNLevo37I87Lp YSAjFgytLY9DphWPfFg0XcnIHVke7B/8WfsUftut7Zw9f9gQF03N28d4ZxVB16ip22 BzTl7QPXBoeBLgv0cenBOPm3tP3da2mBvUeO8/6g= 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.19 153/293] PCI: Return ~0 data on pciconfig_read() CAP_SYS_ADMIN failure Date: Mon, 20 Sep 2021 18:41:55 +0200 Message-Id: <20210920163938.520372466@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@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 @@ -21,8 +21,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);