Skip to content

Commit 8aa37bd

Browse files
author
Al Viro
committed
protect the fetch of ->fd[fd] in do_dup2() from mispredictions
both callers have verified that fd is not greater than ->max_fds; however, misprediction might end up with tofree = fdt->fd[fd]; being speculatively executed. That's wrong for the same reasons why it's wrong in close_fd()/file_close_fd_locked(); the same solution applies - array_index_nospec(fd, fdt->max_fds) could differ from fd only in case of speculative execution on mispredicted path. Cc: [email protected] Signed-off-by: Al Viro <[email protected]>
1 parent 8400291 commit 8aa37bd

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

fs/file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,7 @@ __releases(&files->file_lock)
12481248
* tables and this condition does not arise without those.
12491249
*/
12501250
fdt = files_fdtable(files);
1251+
fd = array_index_nospec(fd, fdt->max_fds);
12511252
tofree = fdt->fd[fd];
12521253
if (!tofree && fd_is_open(fd, fdt))
12531254
goto Ebusy;

0 commit comments

Comments
 (0)