diff --git a/fs/hmdfs/client_writeback.c b/fs/hmdfs/client_writeback.c index d4da7ec482a5b5bea34b21e2793e4120da16d090..d62c286affc1d95f352655f825197a7db4c2cbeb 100644 --- a/fs/hmdfs/client_writeback.c +++ b/fs/hmdfs/client_writeback.c @@ -512,7 +512,7 @@ int hmdfs_init_writeback(struct hmdfs_sb_info *sbi) free_i_wq: destroy_workqueue(hwb->dirty_inode_writeback_wq); free_bdp: - free_percpu(sbi->h_wb->bdp_ratelimits); + free_percpu(hwb->bdp_ratelimits); free_hwb: kfree(hwb); return ret; diff --git a/fs/hmdfs/comm/connection.c b/fs/hmdfs/comm/connection.c index 5a2e5b0f5b027cdb942bf458f8575f280e7afd26..7613da514c7c912d13d79d98a965bd38954b2168 100644 --- a/fs/hmdfs/comm/connection.c +++ b/fs/hmdfs/comm/connection.c @@ -706,7 +706,7 @@ void connection_handshake_recv_handler(struct connection *conn_impl, void *buf, } fallthrough; default: - return; + break; } out: kfree(data); diff --git a/fs/hmdfs/comm/message_verify.c b/fs/hmdfs/comm/message_verify.c index c9eb94d8b615eaf4c0675b5a6756147f2ab6a3a5..fd76658ef16d0161fd8c5907e9665f80a0a30925 100644 --- a/fs/hmdfs/comm/message_verify.c +++ b/fs/hmdfs/comm/message_verify.c @@ -934,7 +934,9 @@ int hmdfs_message_verify(struct hmdfs_peer *con, struct hmdfs_head_cmd *head, goto handle_bad_msg; } - if (head->version == DFS_2_0) { + if (head->version != DFS_2_0) { + err = -EINVAL; + } else { len = le32_to_cpu(head->data_len) - sizeof(struct hmdfs_head_cmd); min = message_length[flag][cmd][HMDFS_MESSAGE_MIN_INDEX]; @@ -973,13 +975,6 @@ int hmdfs_message_verify(struct hmdfs_peer *con, struct hmdfs_head_cmd *head, } handle_bad_msg: - if (err) { - handle_bad_message(con, head, &err); - return err; - } - - if (head->version == DFS_1_0) - return err; // now, DFS_1_0 version do not verify - - return -EINVAL; + handle_bad_message(con, head, &err); + return err; } diff --git a/fs/hmdfs/comm/socket_adapter.c b/fs/hmdfs/comm/socket_adapter.c index eff3d3e1c044d43160176e237f465968500a5283..7005303e3735b455e348cdc08e481b39a7bb0a24 100644 --- a/fs/hmdfs/comm/socket_adapter.c +++ b/fs/hmdfs/comm/socket_adapter.c @@ -409,18 +409,23 @@ int hmdfs_sendmessage_request(struct hmdfs_peer *con, struct hmdfs_head_cmd *head = NULL; bool dec = false; - if (!hmdfs_is_node_online(con)) - return -EAGAIN; + if (!hmdfs_is_node_online(con)) { + ret = -EAGAIN; + goto free_filp; + } if (timeout == TIMEOUT_UNINIT) { hmdfs_err_ratelimited("send msg %d with uninitialized timeout", sm->operations.command); - return -EINVAL; + ret = -EINVAL; + goto free_filp; } head = kzalloc(sizeof(struct hmdfs_head_cmd), GFP_KERNEL); - if (!head) - return -ENOMEM; + if (!head) { + ret = -ENOMEM; + goto free_filp; + } sm->out_buf = NULL; head->magic = HMDFS_MSG_MAGIC; @@ -504,6 +509,11 @@ int hmdfs_sendmessage_request(struct hmdfs_peer *con, hmdfs_dec_msg_idr_process(con); kfree(head); return ret; + +free_filp: + if (sm->local_filp) + fput(sm->local_filp); + return ret; } static int hmdfs_send_slice(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, @@ -1082,7 +1092,7 @@ static void hmdfs_recv_mesg_callback(struct hmdfs_peer *con, void *head, default: hmdfs_err("Fatal! Unexpected msg cmd %d", hmdfs_head->operations.cmd_flag); - break; + goto out_err; } return; diff --git a/fs/hmdfs/hmdfs_server.c b/fs/hmdfs/hmdfs_server.c index dcb15c8b64466fa2c18ba4aa1b326beebaebf8eb..fc02742339700c73444202490ef5696e0bc29d11 100644 --- a/fs/hmdfs/hmdfs_server.c +++ b/fs/hmdfs/hmdfs_server.c @@ -315,8 +315,8 @@ static struct file *get_file_by_fid_and_ver(struct hmdfs_peer *con, __u64 cur_file_ver = hmdfs_server_pack_fid_ver(con, cmd); if (file_ver != cur_file_ver) { - hmdfs_warning("Stale file version %llu for fid %u (ver %llu)", - file_ver, file_id, cur_file_ver); + hmdfs_warning("Stale file version %llu for fid %u", + file_ver, file_id); return ERR_PTR(-EBADF); } diff --git a/fs/hmdfs/hmdfs_share.c b/fs/hmdfs/hmdfs_share.c index c8314a5d7fca6f80942879ada19e3bdcc4b0166b..6b9557d022632cde378ed070dfc6d90f2fd21199 100644 --- a/fs/hmdfs/hmdfs_share.c +++ b/fs/hmdfs/hmdfs_share.c @@ -302,7 +302,7 @@ int hmdfs_check_share_access_permission(struct hmdfs_sb_info *sbi, } -void hmdfs_init_share_table(struct hmdfs_sb_info *sbi) +int hmdfs_init_share_table(struct hmdfs_sb_info *sbi) { spin_lock_init(&sbi->share_table.item_list_lock); INIT_LIST_HEAD(&sbi->share_table.item_list_head); @@ -310,6 +310,10 @@ void hmdfs_init_share_table(struct hmdfs_sb_info *sbi) sbi->share_table.max_cnt = HMDFS_SHARE_ITEMS_MAX; sbi->share_table.share_item_timeout_wq = create_singlethread_workqueue("share_item_timeout_wq"); + + if (!sbi->share_table.share_item_timeout_wq) + return -ENOMEM; + return 0; } void hmdfs_clear_share_table(struct hmdfs_sb_info *sbi) diff --git a/fs/hmdfs/hmdfs_share.h b/fs/hmdfs/hmdfs_share.h index eef53bf19bab9834b832f86e3e28d8335bd16c01..3c055805bd6dd1327be47790a7f036cf1d1cb5b8 100644 --- a/fs/hmdfs/hmdfs_share.h +++ b/fs/hmdfs/hmdfs_share.h @@ -60,7 +60,7 @@ void hmdfs_close_share_item(struct hmdfs_sb_info *sbi, struct file *file, int hmdfs_check_share_access_permission(struct hmdfs_sb_info *sbi, const char *filename, char *cid); -void hmdfs_init_share_table(struct hmdfs_sb_info *sbi); +int hmdfs_init_share_table(struct hmdfs_sb_info *sbi); void hmdfs_clear_share_table(struct hmdfs_sb_info *sbi); int hmdfs_clear_first_item(struct hmdfs_share_table *st); diff --git a/fs/hmdfs/inode_root.c b/fs/hmdfs/inode_root.c index 30d0ca6a2264020fd54c9e856a2dc5497214a787..b3b2b5c2b2fc2c0b3a0a8d60cf010f27632b33c9 100644 --- a/fs/hmdfs/inode_root.c +++ b/fs/hmdfs/inode_root.c @@ -153,7 +153,7 @@ struct dentry *hmdfs_device_lookup(struct inode *parent_inode, ret_dentry = ERR_PTR(err); goto out; } - memcpy(cid, d_name, HMDFS_CID_SIZE); + strncpy(cid, d_name, HMDFS_CID_SIZE); cid[HMDFS_CID_SIZE] = '\0'; con = hmdfs_lookup_from_cid(sbi, cid); if (!con) { diff --git a/fs/hmdfs/main.c b/fs/hmdfs/main.c index d0a41061bb2f343317232f54e8a4d8255c1e5673..53d6989179695fb1f27746d30b03d97d86190561 100644 --- a/fs/hmdfs/main.c +++ b/fs/hmdfs/main.c @@ -712,7 +712,9 @@ static int hmdfs_init_sbi(struct hmdfs_sb_info *sbi) mutex_init(&sbi->connections.node_lock); INIT_LIST_HEAD(&sbi->connections.node_list); - hmdfs_init_share_table(sbi); + ret = hmdfs_init_share_table(sbi); + if (ret) + goto out; init_waitqueue_head(&sbi->async_readdir_wq); INIT_LIST_HEAD(&sbi->async_readdir_msg_list); INIT_LIST_HEAD(&sbi->async_readdir_work_list); @@ -762,6 +764,7 @@ static int hmdfs_update_dst(struct hmdfs_sb_info *sbi) goto out_err; } kfree(sbi->local_dst); + sbi->local_dst = NULL; len = strlen(sbi->real_dst) + strlen(path_local) + 1; if (len > PATH_MAX) { @@ -954,6 +957,10 @@ static struct dentry *hmdfs_mount(struct file_system_type *fs_type, int flags, .dev_name = dev_name, .raw_data = raw_data, }; + + /* hmdfs needs a valid dev_name to get the lower_sb's metadata */ + if (!dev_name || !*dev_name) + return ERR_PTR(-EINVAL); return mount_nodev(fs_type, flags, &priv, hmdfs_fill_super); } diff --git a/fs/hmdfs/super.c b/fs/hmdfs/super.c index 52cc857f5e45f55a874d219d673b35cfcc97c73e..a4b1170153b373030b2fc070ebd0a2f5d342d86e 100644 --- a/fs/hmdfs/super.c +++ b/fs/hmdfs/super.c @@ -63,6 +63,8 @@ static int hmdfs_match_strdup(const substring_t *s, char **dst) if (!dup) return -ENOMEM; + if (*dst) + kfree(*dst); *dst = dup; return 0;