[Devel] [PATCH] fs: Fix race with old fdt parallel reuse

Kirill Tkhai ktkhai at virtuozzo.com
Wed Mar 28 15:18:57 MSK 2018


We own files->resize_in_progress in this moment,
but it's only seen by guys, who expands the fdt.
If someone wants to use fd inside old fdt max number,
it just doesn't look at this.

So, let's check old maximum fd after lock is
acquired to see such the parallel users.

https://jira.sw.ru/browse/PSBM-82984

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 fs/file.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/file.c b/fs/file.c
index b85e8ee6143b..e51acd2f5e5e 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -186,8 +186,7 @@ static int expand_fdtable(struct files_struct *files, int nr, bool shrink)
 	if (unlikely(shrink)) {
 		int i;
 		i = find_last_bit(cur_fdt->open_fds, cur_fdt->max_fds);
-		i = fdtable_align(i);
-		if (i == cur_fdt->max_fds) {
+		if (i >= new_fdt->max_fds) {
 			__free_fdtable(new_fdt);
 			return 1;
 		}



More information about the Devel mailing list