Skip to content

Commit 0f166bf

Browse files
t-8chbrauner
authored andcommitted
select: store end_time as timespec64 in restart block
Storing the end time seconds as 'unsigned long' can lead to truncation on 32-bit architectures if assigned from the 64-bit timespec64::tv_sec. As the select() core uses timespec64 consistently, also use that in the restart block. This also allows the simplification of the accessors. Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Link: https://patch.msgid.link/20251223-restart-block-expiration-v2-1-8e33e5df7359@linutronix.de Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 3685744 commit 0f166bf

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

fs/select.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,14 +1038,11 @@ static long do_restart_poll(struct restart_block *restart_block)
10381038
{
10391039
struct pollfd __user *ufds = restart_block->poll.ufds;
10401040
int nfds = restart_block->poll.nfds;
1041-
struct timespec64 *to = NULL, end_time;
1041+
struct timespec64 *to = NULL;
10421042
int ret;
10431043

1044-
if (restart_block->poll.has_timeout) {
1045-
end_time.tv_sec = restart_block->poll.tv_sec;
1046-
end_time.tv_nsec = restart_block->poll.tv_nsec;
1047-
to = &end_time;
1048-
}
1044+
if (restart_block->poll.has_timeout)
1045+
to = &restart_block->poll.end_time;
10491046

10501047
ret = do_sys_poll(ufds, nfds, to);
10511048

@@ -1077,8 +1074,7 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, unsigned int, nfds,
10771074
restart_block->poll.nfds = nfds;
10781075

10791076
if (timeout_msecs >= 0) {
1080-
restart_block->poll.tv_sec = end_time.tv_sec;
1081-
restart_block->poll.tv_nsec = end_time.tv_nsec;
1077+
restart_block->poll.end_time = end_time;
10821078
restart_block->poll.has_timeout = 1;
10831079
} else
10841080
restart_block->poll.has_timeout = 0;

include/linux/restart_block.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define __LINUX_RESTART_BLOCK_H
77

88
#include <linux/compiler.h>
9+
#include <linux/time64.h>
910
#include <linux/types.h>
1011

1112
struct __kernel_timespec;
@@ -50,8 +51,7 @@ struct restart_block {
5051
struct pollfd __user *ufds;
5152
int nfds;
5253
int has_timeout;
53-
unsigned long tv_sec;
54-
unsigned long tv_nsec;
54+
struct timespec64 end_time;
5555
} poll;
5656
};
5757
};

0 commit comments

Comments
 (0)