From be93a741db16f7daa8394909b7e0fb0a986d4977 Mon Sep 17 00:00:00 2001 From: linqiheng Date: Tue, 10 Jan 2023 15:13:53 +0000 Subject: [PATCH] hmdfs: avoid recv_task racing when concurrently handle cmds When CMD_UPDATE_SOCKET and CMD_OFF_LINE operate on the same fd concurrently, there is no lock protection after acquiring the same connect_handle, which is released and emptied by tcp_close_socket() before the wake_up_process() call. Signed-off-by: linqiheng --- fs/hmdfs/comm/device_node.c | 2 ++ fs/hmdfs/hmdfs.h | 1 + fs/hmdfs/main.c | 1 + 3 files changed, 4 insertions(+) diff --git a/fs/hmdfs/comm/device_node.c b/fs/hmdfs/comm/device_node.c index 7c2bac914bb4..0f2585de61fe 100644 --- a/fs/hmdfs/comm/device_node.c +++ b/fs/hmdfs/comm/device_node.c @@ -232,9 +232,11 @@ static ssize_t sbi_cmd_store(struct kobject *kobj, struct sbi_attribute *attr, hmdfs_err("Illegal cmd : cmd = %d", cmd); return len; } + mutex_lock(&sbi->cmd_handler_mutex); hmdfs_info("Recved cmd: %s", cmd2str(cmd)); if (cmd_handler[cmd]) cmd_handler[cmd](buf, len, sbi); + mutex_unlock(&sbi->cmd_handler_mutex); return len; } diff --git a/fs/hmdfs/hmdfs.h b/fs/hmdfs/hmdfs.h index 9157c55ba392..45fcf9f9b3f3 100644 --- a/fs/hmdfs/hmdfs.h +++ b/fs/hmdfs/hmdfs.h @@ -169,6 +169,7 @@ struct hmdfs_sb_info { /* To bridge the userspace utils */ struct kfifo notify_fifo; spinlock_t notify_fifo_lock; + struct mutex cmd_handler_mutex; /* For reboot detect */ uint64_t boot_cookie; diff --git a/fs/hmdfs/main.c b/fs/hmdfs/main.c index d0a41061bb2f..f321391e15f1 100644 --- a/fs/hmdfs/main.c +++ b/fs/hmdfs/main.c @@ -692,6 +692,7 @@ static int hmdfs_init_sbi(struct hmdfs_sb_info *sbi) ret = 0; spin_lock_init(&sbi->notify_fifo_lock); + mutex_init(&sbi->cmd_handler_mutex); sbi->s_case_sensitive = false; sbi->s_features = HMDFS_FEATURE_READPAGES | HMDFS_FEATURE_READPAGES_OPEN | -- Gitee