* [PATCH 1/2] PCI: syscall: Set the ~0 value on access failure
@ 2021-07-29 23:37 Krzysztof Wilczyński
2021-07-29 23:37 ` [PATCH 2/2] PCI: syscall: Change type of err variable from long to int Krzysztof Wilczyński
0 siblings, 1 reply; 3+ messages in thread
From: Krzysztof Wilczyński @ 2021-07-29 23:37 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci
The pciconfig_read syscall has a special provision to handle users that
don't check the return value for a possible error code and rely solely
on checking for the value of ~0 to be set as a result of the PCI
configuration read failure.
The commit e4585da22ad0 ("pci syscall.c: Switch to refcounting API")
changed this semantic of setting the results to the value of ~0 to
indicate read error concerning CAP_SYS_ADMIN capability flag validation.
After this commit, the syscall would simply return -EPERM early should
the user does not have the required permissions. This changes the
original behaviour which might not be something that the users of this
syscall expect, especially since some of the problematic users do not
check the return code whatsoever.
Thus, restore the original behaviour of setting the results to a value
of ~0 on read failure to include the capabilities check.
Fixes: e4585da22ad0 ("pci syscall.c: Switch to refcounting API")
Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
---
drivers/pci/syscall.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/syscall.c b/drivers/pci/syscall.c
index 8b003c890b87..b842af1e06b8 100644
--- a/drivers/pci/syscall.c
+++ b/drivers/pci/syscall.c
@@ -22,8 +22,9 @@ SYSCALL_DEFINE5(pciconfig_read, unsigned long, bus, unsigned long, dfn,
long err;
int cfg_ret;
+ err = -EPERM;
if (!capable(CAP_SYS_ADMIN))
- return -EPERM;
+ goto error;
err = -ENODEV;
dev = pci_get_domain_bus_and_slot(0, bus, dfn);
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] PCI: syscall: Change type of err variable from long to int
2021-07-29 23:37 [PATCH 1/2] PCI: syscall: Set the ~0 value on access failure Krzysztof Wilczyński
@ 2021-07-29 23:37 ` Krzysztof Wilczyński
2021-07-30 21:06 ` Bjorn Helgaas
0 siblings, 1 reply; 3+ messages in thread
From: Krzysztof Wilczyński @ 2021-07-29 23:37 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci
The pciconfig_read syscall uses an err variable is currently declared as
long and even though it matches the function signature as generated by
the SYSCALL_DEFINEx() macro is a bit wasteful as the syscall returns
a handful of simple error codes.
Thus, change the err value type from long to int to lower the storage
requirements and also align it with the pciconfig_write syscall.
Related:
commit ef9e4005cbaf ("PCI: Align checking of syscall user config accessors")
Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
---
drivers/pci/syscall.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/pci/syscall.c b/drivers/pci/syscall.c
index b842af1e06b8..525f16caed1d 100644
--- a/drivers/pci/syscall.c
+++ b/drivers/pci/syscall.c
@@ -19,8 +19,7 @@ SYSCALL_DEFINE5(pciconfig_read, unsigned long, bus, unsigned long, dfn,
u8 byte;
u16 word;
u32 dword;
- long err;
- int cfg_ret;
+ int err, cfg_ret;
err = -EPERM;
if (!capable(CAP_SYS_ADMIN))
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] PCI: syscall: Change type of err variable from long to int
2021-07-29 23:37 ` [PATCH 2/2] PCI: syscall: Change type of err variable from long to int Krzysztof Wilczyński
@ 2021-07-30 21:06 ` Bjorn Helgaas
0 siblings, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2021-07-30 21:06 UTC (permalink / raw)
To: Krzysztof Wilczyński; +Cc: Bjorn Helgaas, linux-pci
On Thu, Jul 29, 2021 at 11:37:55PM +0000, Krzysztof Wilczyński wrote:
> The pciconfig_read syscall uses an err variable is currently declared as
> long and even though it matches the function signature as generated by
> the SYSCALL_DEFINEx() macro is a bit wasteful as the syscall returns
> a handful of simple error codes.
>
> Thus, change the err value type from long to int to lower the storage
> requirements and also align it with the pciconfig_write syscall.
>
> Related:
> commit ef9e4005cbaf ("PCI: Align checking of syscall user config accessors")
>
> Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
Applied both to pci/enumeration for v5.15, thanks!
> ---
> drivers/pci/syscall.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/pci/syscall.c b/drivers/pci/syscall.c
> index b842af1e06b8..525f16caed1d 100644
> --- a/drivers/pci/syscall.c
> +++ b/drivers/pci/syscall.c
> @@ -19,8 +19,7 @@ SYSCALL_DEFINE5(pciconfig_read, unsigned long, bus, unsigned long, dfn,
> u8 byte;
> u16 word;
> u32 dword;
> - long err;
> - int cfg_ret;
> + int err, cfg_ret;
>
> err = -EPERM;
> if (!capable(CAP_SYS_ADMIN))
> --
> 2.32.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-30 21:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-29 23:37 [PATCH 1/2] PCI: syscall: Set the ~0 value on access failure Krzysztof Wilczyński
2021-07-29 23:37 ` [PATCH 2/2] PCI: syscall: Change type of err variable from long to int Krzysztof Wilczyński
2021-07-30 21:06 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).