fs: Fix race with old fdt parallel reuse

Submitted by Kirill Tkhai on March 28, 2018, 12:18 p.m.

Details

Message ID 152223949815.23503.7948097519511890665.stgit@localhost.localdomain
State New
Series "fs: Fix race with old fdt parallel reuse"
Headers show

Commit Message

Kirill Tkhai March 28, 2018, 12:18 p.m.
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@virtuozzo.com>
---
 fs/file.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Patch hide | download patch | download mbox

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;
 		}

Comments

Kirill Gorkunov March 28, 2018, 1:44 p.m.
On Wed, Mar 28, 2018 at 03:18:57PM +0300, Kirill Tkhai wrote:
> 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@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>