Skip to content

Fix ERESTARTSYS leak to userspace - #319

Closed
dmitrym1 wants to merge 1 commit into
Xilinx:masterfrom
dmitrym1:fix_ERESTARTSYS_leak_to_userspace
Closed

Fix ERESTARTSYS leak to userspace#319
dmitrym1 wants to merge 1 commit into
Xilinx:masterfrom
dmitrym1:fix_ERESTARTSYS_leak_to_userspace

Conversation

@dmitrym1

@dmitrym1 dmitrym1 commented Jan 17, 2025

Copy link
Copy Markdown

Fix ERESTARTSYS leak to userspace by replacing it with the appropriate for userspace error codes. Fixes #320

@jason77-wang

Copy link
Copy Markdown

Hi, what is your change used for? what problem do you find with the current design?

@dmitrym1

Copy link
Copy Markdown
Author

Hi @jason77-wang, current code returns error 512 in case of timeout of r/w transaction and in case of blocking read of event device. This error code is undefined in userspace and it is a common practice to keep such error codes inside kernel and instead return one of defined error codes. So that programmers don't puzzle over that error code (it's non standard so it is not described anywhere) and instead have a clear understanding of why their syscall returns an error and what to do with it. It may break existing userspace apps if they explicitly expect error code 512, in this case you need either to modify code of such apps, or just don't include that change in your XDMA module build.

@jason77-wang

Copy link
Copy Markdown

Hi @jason77-wang, current code returns error 512 in case of timeout of r/w transaction and in case of blocking read of event device. This error code is undefined in userspace and it is a common practice to keep such error codes inside kernel and instead return one of defined error codes. So that programmers don't puzzle over that error code (it's non standard so it is not described anywhere) and instead have a clear understanding of why their syscall returns an error and what to do with it. It may break existing userspace apps if they explicitly expect error code 512, in this case you need either to modify code of such apps, or just don't include that change in your XDMA module build.

Got it. thanks.

@devegali

Copy link
Copy Markdown
Collaborator

Changes are already part of master branch.

@devegali devegali closed this Jun 20, 2026
@alonbl

alonbl commented Jun 20, 2026

Copy link
Copy Markdown

@devegali : are you sure this was merged properly? I can see the following missing.

diff --git a/XDMA/linux-kernel/xdma/cdev_events.c b/XDMA/linux-kernel/xdma/cdev_events.c
index 4942d96..2a9c0ab 100644
--- a/XDMA/linux-kernel/xdma/cdev_events.c
+++ b/XDMA/linux-kernel/xdma/cdev_events.c
@@ -59,7 +59,7 @@ static ssize_t char_events_read(struct file *file, char __user *buf,
 
        /* wait_event_interruptible() was interrupted by a signal */
        if (rv == -ERESTARTSYS)
-               return -ERESTARTSYS;
+               return -EAGAIN;
 
        /* atomically decide which events are passed to the user */
        spin_lock_irqsave(&user_irq->events_lock, flags);

alonbl pushed a commit to alonbl/dma_ip_drivers that referenced this pull request Jun 20, 2026
Replace it with the appropriate for userspace error codes

Bug: Xilinx#319
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ERESTARTSYS (aka Error 512) should not leak to userspace

4 participants