Skip to contentSkip to conversation

fs: prevent out-of-bounds array speculation when closing a file descriptor

PATCH In review Theodore Ts'o 2 participants 5 messages Jul 23, 2020 – Mar 13, 2023 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: prevent out-of-bounds array speculation when closing a file descriptor

Google-Bug-Id: 114199369

---
 fs/file.c | 1 +
 1 file changed, 1 insertion(+)
fs/file.c +1 -0
index abb8b7081d7a..73189eaad1df 100644
@@ -632,6 +632,7 @@ int __close_fd(struct files_struct *files, unsigned fd)
 	fdt = files_fdtable(files);
 	if (fd >= fdt->max_fds)
 		goto out_unlock;
+	fd = array_index_nospec(fd, fdt->max_fds);
 	file = fdt->fd[fd];
 	if (!file)
 		goto out_unlock;
Signature · 1 line
2.24.1
Tested-by on v1 1/1
#1 lore raw
Quoted 3 lines · Theodore Ts'o

Google-Bug-Id: 114199369

- Sedat -

Quoted 19 lines
---
 fs/file.c | 1 +
 1 file changed, 1 insertion(+)
fs/file.c +1 -1
index abb8b7081d7a..73189eaad1df 100644
@@ -632,6 +632,7 @@ int __close_fd(struct files_struct *files, unsigned fd)
        fdt = files_fdtable(files);
        if (fd >= fdt->max_fds)
                goto out_unlock;
+       fd = array_index_nospec(fd, fdt->max_fds);
        file = fdt->fd[fd];
        if (!file)
                goto out_unlock;
--

2.24.1

#2 lore raw
Quoted 8 lines · Sedat Dilek
Quoted 3 lines · Theodore Ts'o

Google-Bug-Id: 114199369

Ping.

What is the status of this patch?

- Sedat -

Quoted 20 lines
Quoted 20 lines
---
 fs/file.c | 1 +
 1 file changed, 1 insertion(+)
fs/file.cfs: prevent out-of-bounds array speculation when closing a file descriptor renamed from fs/file.c +1 -1
index abb8b7081d7a..73189eaad1df 100644
@@ -632,6 +632,7 @@ int __close_fd(struct files_struct *files, unsigned fd)
        fdt = files_fdtable(files);
        if (fd >= fdt->max_fds)
                goto out_unlock;fs: prevent out-of-bounds array speculation when closing a file descriptor fs: prevent out-of-bounds array speculation when closing a file descriptor fs: prevent out-of-bounds array speculation when closing a file descriptor
+       fd = array_index_nospec(fd, fdt->max_fds);
        file = fdt->fd[fd];
        if (!file)
                goto out_unlock;
--

2.24.1

#3 lore raw
Quoted 8 lines · Sedat Dilek
Quoted 6 lines · Sedat Dilek
Quoted 3 lines · Theodore Ts'o

Google-Bug-Id: 114199369

Quoted 7 lines
Quoted 2 lines

Ping.

What is the status of this patch?

Friendly ping again.

- Sedat -

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines

---
 fs/file.c | 1 +
 1 file changed, 1 insertion(+)
fs/file.cfs: prevent out-of-bounds array speculation when closing a file descriptor renamed from fs/file.c +1 -1
index abb8b7081d7a..73189eaad1df 100644
@@ -632,6 +632,7 @@ int __close_fd(struct files_struct *files, unsigned fd)
        fdt = files_fdtable(files);
        if (fd >= fdt->max_fds)
                goto out_unlock;fs: prevent out-of-bounds array speculation when closing a file descriptor fs: prevent out-of-bounds array speculation when closing a file descriptor fs: prevent out-of-bounds array speculation when closing a file descriptor
+       fd = array_index_nospec(fd, fdt->max_fds);
        file = fdt->fd[fd];
        if (!file)
                goto out_unlock;
--

2.24.1

#4 lore raw
Quoted 13 lines · Sedat Dilek
Quoted 11 lines · Sedat Dilek
Quoted 8 lines · Sedat Dilek
Quoted 3 lines · Theodore Ts'o

Google-Bug-Id: 114199369

Quoted 7 lines
Quoted 4 lines

Ping.

What is the status of this patch?

Friendly ping again.

Finally upstreamed :-).

-Sedat-

[1] https://git.kernel.org/linus/609d54441493c99f21c1823dfd66fa7f4c512ff4

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines

---
 fs/file.c | 1 +
 1 file changed, 1 insertion(+)
fs/file.cfs: prevent out-of-bounds array speculation when closing a file descriptor renamed from fs/file.c +1 -1
index abb8b7081d7a..73189eaad1df 100644
@@ -632,6 +632,7 @@ int __close_fd(struct files_struct *files, unsigned fd)
        fdt = files_fdtable(files);
        if (fd >= fdt->max_fds)
                goto out_unlock;fs: prevent out-of-bounds array speculation when closing a file descriptor fs: prevent out-of-bounds array speculation when closing a file descriptor fs: prevent out-of-bounds array speculation when closing a file descriptor
+       fd = array_index_nospec(fd, fdt->max_fds);
        file = fdt->fd[fd];
        if (!file)
                goto out_unlock;
--

2.24.1