Commit 37faf07b authored by Linus Torvalds's avatar Linus Torvalds

Merge tag '6.6-rc4-ksmbd-server-fixes' of git://git.samba.org/ksmbd

Pull smb server fixes from Steve French:
 "Six SMB3 server fixes for various races found by RO0T Lab of Huawei:

   - Fix oops when racing between oplock break ack and freeing file

   - Simultaneous request fixes for parallel logoffs, and for parallel
     lock requests

   - Fixes for tree disconnect race, session expire race, and close/open
     race"

* tag '6.6-rc4-ksmbd-server-fixes' of git://git.samba.org/ksmbd:
  ksmbd: fix race condition between tree conn lookup and disconnect
  ksmbd: fix race condition from parallel smb2 lock requests
  ksmbd: fix race condition from parallel smb2 logoff requests
  ksmbd: fix uaf in smb20_oplock_break_ack
  ksmbd: fix race condition with fp
  ksmbd: fix race condition between session lookup and expire
parents f707e40d 33b235a6
...@@ -84,6 +84,8 @@ struct ksmbd_conn *ksmbd_conn_alloc(void) ...@@ -84,6 +84,8 @@ struct ksmbd_conn *ksmbd_conn_alloc(void)
spin_lock_init(&conn->llist_lock); spin_lock_init(&conn->llist_lock);
INIT_LIST_HEAD(&conn->lock_list); INIT_LIST_HEAD(&conn->lock_list);
init_rwsem(&conn->session_lock);
down_write(&conn_list_lock); down_write(&conn_list_lock);
list_add(&conn->conns_list, &conn_list); list_add(&conn->conns_list, &conn_list);
up_write(&conn_list_lock); up_write(&conn_list_lock);
......
...@@ -50,6 +50,7 @@ struct ksmbd_conn { ...@@ -50,6 +50,7 @@ struct ksmbd_conn {
struct nls_table *local_nls; struct nls_table *local_nls;
struct unicode_map *um; struct unicode_map *um;
struct list_head conns_list; struct list_head conns_list;
struct rw_semaphore session_lock;
/* smb session 1 per user */ /* smb session 1 per user */
struct xarray sessions; struct xarray sessions;
unsigned long last_active; unsigned long last_active;
......
...@@ -73,7 +73,10 @@ ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess, ...@@ -73,7 +73,10 @@ ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess,
tree_conn->user = sess->user; tree_conn->user = sess->user;
tree_conn->share_conf = sc; tree_conn->share_conf = sc;
tree_conn->t_state = TREE_NEW;
status.tree_conn = tree_conn; status.tree_conn = tree_conn;
atomic_set(&tree_conn->refcount, 1);
init_waitqueue_head(&tree_conn->refcount_q);
ret = xa_err(xa_store(&sess->tree_conns, tree_conn->id, tree_conn, ret = xa_err(xa_store(&sess->tree_conns, tree_conn->id, tree_conn,
GFP_KERNEL)); GFP_KERNEL));
...@@ -93,14 +96,33 @@ ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess, ...@@ -93,14 +96,33 @@ ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess,
return status; return status;
} }
void ksmbd_tree_connect_put(struct ksmbd_tree_connect *tcon)
{
/*
* Checking waitqueue to releasing tree connect on
* tree disconnect. waitqueue_active is safe because it
* uses atomic operation for condition.
*/
if (!atomic_dec_return(&tcon->refcount) &&
waitqueue_active(&tcon->refcount_q))
wake_up(&tcon->refcount_q);
}
int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess, int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess,
struct ksmbd_tree_connect *tree_conn) struct ksmbd_tree_connect *tree_conn)
{ {
int ret; int ret;
write_lock(&sess->tree_conns_lock);
xa_erase(&sess->tree_conns, tree_conn->id);
write_unlock(&sess->tree_conns_lock);
if (!atomic_dec_and_test(&tree_conn->refcount))
wait_event(tree_conn->refcount_q,
atomic_read(&tree_conn->refcount) == 0);
ret = ksmbd_ipc_tree_disconnect_request(sess->id, tree_conn->id); ret = ksmbd_ipc_tree_disconnect_request(sess->id, tree_conn->id);
ksmbd_release_tree_conn_id(sess, tree_conn->id); ksmbd_release_tree_conn_id(sess, tree_conn->id);
xa_erase(&sess->tree_conns, tree_conn->id);
ksmbd_share_config_put(tree_conn->share_conf); ksmbd_share_config_put(tree_conn->share_conf);
kfree(tree_conn); kfree(tree_conn);
return ret; return ret;
...@@ -111,11 +133,15 @@ struct ksmbd_tree_connect *ksmbd_tree_conn_lookup(struct ksmbd_session *sess, ...@@ -111,11 +133,15 @@ struct ksmbd_tree_connect *ksmbd_tree_conn_lookup(struct ksmbd_session *sess,
{ {
struct ksmbd_tree_connect *tcon; struct ksmbd_tree_connect *tcon;
read_lock(&sess->tree_conns_lock);
tcon = xa_load(&sess->tree_conns, id); tcon = xa_load(&sess->tree_conns, id);
if (tcon) { if (tcon) {
if (test_bit(TREE_CONN_EXPIRE, &tcon->status)) if (tcon->t_state != TREE_CONNECTED)
tcon = NULL;
else if (!atomic_inc_not_zero(&tcon->refcount))
tcon = NULL; tcon = NULL;
} }
read_unlock(&sess->tree_conns_lock);
return tcon; return tcon;
} }
...@@ -129,8 +155,18 @@ int ksmbd_tree_conn_session_logoff(struct ksmbd_session *sess) ...@@ -129,8 +155,18 @@ int ksmbd_tree_conn_session_logoff(struct ksmbd_session *sess)
if (!sess) if (!sess)
return -EINVAL; return -EINVAL;
xa_for_each(&sess->tree_conns, id, tc) xa_for_each(&sess->tree_conns, id, tc) {
write_lock(&sess->tree_conns_lock);
if (tc->t_state == TREE_DISCONNECTED) {
write_unlock(&sess->tree_conns_lock);
ret = -ENOENT;
continue;
}
tc->t_state = TREE_DISCONNECTED;
write_unlock(&sess->tree_conns_lock);
ret |= ksmbd_tree_conn_disconnect(sess, tc); ret |= ksmbd_tree_conn_disconnect(sess, tc);
}
xa_destroy(&sess->tree_conns); xa_destroy(&sess->tree_conns);
return ret; return ret;
} }
...@@ -14,7 +14,11 @@ struct ksmbd_share_config; ...@@ -14,7 +14,11 @@ struct ksmbd_share_config;
struct ksmbd_user; struct ksmbd_user;
struct ksmbd_conn; struct ksmbd_conn;
#define TREE_CONN_EXPIRE 1 enum {
TREE_NEW = 0,
TREE_CONNECTED,
TREE_DISCONNECTED
};
struct ksmbd_tree_connect { struct ksmbd_tree_connect {
int id; int id;
...@@ -27,7 +31,9 @@ struct ksmbd_tree_connect { ...@@ -27,7 +31,9 @@ struct ksmbd_tree_connect {
int maximal_access; int maximal_access;
bool posix_extensions; bool posix_extensions;
unsigned long status; atomic_t refcount;
wait_queue_head_t refcount_q;
unsigned int t_state;
}; };
struct ksmbd_tree_conn_status { struct ksmbd_tree_conn_status {
...@@ -46,6 +52,7 @@ struct ksmbd_session; ...@@ -46,6 +52,7 @@ struct ksmbd_session;
struct ksmbd_tree_conn_status struct ksmbd_tree_conn_status
ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess, ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess,
const char *share_name); const char *share_name);
void ksmbd_tree_connect_put(struct ksmbd_tree_connect *tcon);
int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess, int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess,
struct ksmbd_tree_connect *tree_conn); struct ksmbd_tree_connect *tree_conn);
......
...@@ -174,7 +174,7 @@ static void ksmbd_expire_session(struct ksmbd_conn *conn) ...@@ -174,7 +174,7 @@ static void ksmbd_expire_session(struct ksmbd_conn *conn)
unsigned long id; unsigned long id;
struct ksmbd_session *sess; struct ksmbd_session *sess;
down_write(&sessions_table_lock); down_write(&conn->session_lock);
xa_for_each(&conn->sessions, id, sess) { xa_for_each(&conn->sessions, id, sess) {
if (sess->state != SMB2_SESSION_VALID || if (sess->state != SMB2_SESSION_VALID ||
time_after(jiffies, time_after(jiffies,
...@@ -185,7 +185,7 @@ static void ksmbd_expire_session(struct ksmbd_conn *conn) ...@@ -185,7 +185,7 @@ static void ksmbd_expire_session(struct ksmbd_conn *conn)
continue; continue;
} }
} }
up_write(&sessions_table_lock); up_write(&conn->session_lock);
} }
int ksmbd_session_register(struct ksmbd_conn *conn, int ksmbd_session_register(struct ksmbd_conn *conn,
...@@ -227,7 +227,9 @@ void ksmbd_sessions_deregister(struct ksmbd_conn *conn) ...@@ -227,7 +227,9 @@ void ksmbd_sessions_deregister(struct ksmbd_conn *conn)
} }
} }
} }
up_write(&sessions_table_lock);
down_write(&conn->session_lock);
xa_for_each(&conn->sessions, id, sess) { xa_for_each(&conn->sessions, id, sess) {
unsigned long chann_id; unsigned long chann_id;
struct channel *chann; struct channel *chann;
...@@ -244,7 +246,7 @@ void ksmbd_sessions_deregister(struct ksmbd_conn *conn) ...@@ -244,7 +246,7 @@ void ksmbd_sessions_deregister(struct ksmbd_conn *conn)
ksmbd_session_destroy(sess); ksmbd_session_destroy(sess);
} }
} }
up_write(&sessions_table_lock); up_write(&conn->session_lock);
} }
struct ksmbd_session *ksmbd_session_lookup(struct ksmbd_conn *conn, struct ksmbd_session *ksmbd_session_lookup(struct ksmbd_conn *conn,
...@@ -252,9 +254,11 @@ struct ksmbd_session *ksmbd_session_lookup(struct ksmbd_conn *conn, ...@@ -252,9 +254,11 @@ struct ksmbd_session *ksmbd_session_lookup(struct ksmbd_conn *conn,
{ {
struct ksmbd_session *sess; struct ksmbd_session *sess;
down_read(&conn->session_lock);
sess = xa_load(&conn->sessions, id); sess = xa_load(&conn->sessions, id);
if (sess) if (sess)
sess->last_active = jiffies; sess->last_active = jiffies;
up_read(&conn->session_lock);
return sess; return sess;
} }
...@@ -351,6 +355,7 @@ static struct ksmbd_session *__session_create(int protocol) ...@@ -351,6 +355,7 @@ static struct ksmbd_session *__session_create(int protocol)
xa_init(&sess->ksmbd_chann_list); xa_init(&sess->ksmbd_chann_list);
xa_init(&sess->rpc_handle_list); xa_init(&sess->rpc_handle_list);
sess->sequence_number = 1; sess->sequence_number = 1;
rwlock_init(&sess->tree_conns_lock);
ret = __init_smb2_session(sess); ret = __init_smb2_session(sess);
if (ret) if (ret)
......
...@@ -60,6 +60,7 @@ struct ksmbd_session { ...@@ -60,6 +60,7 @@ struct ksmbd_session {
struct ksmbd_file_table file_table; struct ksmbd_file_table file_table;
unsigned long last_active; unsigned long last_active;
rwlock_t tree_conns_lock;
}; };
static inline int test_session_flag(struct ksmbd_session *sess, int bit) static inline int test_session_flag(struct ksmbd_session *sess, int bit)
......
...@@ -241,6 +241,8 @@ static void __handle_ksmbd_work(struct ksmbd_work *work, ...@@ -241,6 +241,8 @@ static void __handle_ksmbd_work(struct ksmbd_work *work,
} while (is_chained == true); } while (is_chained == true);
send: send:
if (work->tcon)
ksmbd_tree_connect_put(work->tcon);
smb3_preauth_hash_rsp(work); smb3_preauth_hash_rsp(work);
if (work->sess && work->sess->enc && work->encrypted && if (work->sess && work->sess->enc && work->encrypted &&
conn->ops->encrypt_resp) { conn->ops->encrypt_resp) {
......
...@@ -1993,6 +1993,9 @@ int smb2_tree_connect(struct ksmbd_work *work) ...@@ -1993,6 +1993,9 @@ int smb2_tree_connect(struct ksmbd_work *work)
if (conn->posix_ext_supported) if (conn->posix_ext_supported)
status.tree_conn->posix_extensions = true; status.tree_conn->posix_extensions = true;
write_lock(&sess->tree_conns_lock);
status.tree_conn->t_state = TREE_CONNECTED;
write_unlock(&sess->tree_conns_lock);
rsp->StructureSize = cpu_to_le16(16); rsp->StructureSize = cpu_to_le16(16);
out_err1: out_err1:
rsp->Capabilities = 0; rsp->Capabilities = 0;
...@@ -2122,27 +2125,50 @@ int smb2_tree_disconnect(struct ksmbd_work *work) ...@@ -2122,27 +2125,50 @@ int smb2_tree_disconnect(struct ksmbd_work *work)
ksmbd_debug(SMB, "request\n"); ksmbd_debug(SMB, "request\n");
if (!tcon) {
ksmbd_debug(SMB, "Invalid tid %d\n", req->hdr.Id.SyncId.TreeId);
rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
err = -ENOENT;
goto err_out;
}
ksmbd_close_tree_conn_fds(work);
write_lock(&sess->tree_conns_lock);
if (tcon->t_state == TREE_DISCONNECTED) {
write_unlock(&sess->tree_conns_lock);
rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
err = -ENOENT;
goto err_out;
}
WARN_ON_ONCE(atomic_dec_and_test(&tcon->refcount));
tcon->t_state = TREE_DISCONNECTED;
write_unlock(&sess->tree_conns_lock);
err = ksmbd_tree_conn_disconnect(sess, tcon);
if (err) {
rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
goto err_out;
}
work->tcon = NULL;
rsp->StructureSize = cpu_to_le16(4); rsp->StructureSize = cpu_to_le16(4);
err = ksmbd_iov_pin_rsp(work, rsp, err = ksmbd_iov_pin_rsp(work, rsp,
sizeof(struct smb2_tree_disconnect_rsp)); sizeof(struct smb2_tree_disconnect_rsp));
if (err) { if (err) {
rsp->hdr.Status = STATUS_INSUFFICIENT_RESOURCES; rsp->hdr.Status = STATUS_INSUFFICIENT_RESOURCES;
smb2_set_err_rsp(work); goto err_out;
return err;
} }
if (!tcon || test_and_set_bit(TREE_CONN_EXPIRE, &tcon->status)) { return 0;
ksmbd_debug(SMB, "Invalid tid %d\n", req->hdr.Id.SyncId.TreeId);
rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED; err_out:
smb2_set_err_rsp(work); smb2_set_err_rsp(work);
return -ENOENT; return err;
}
ksmbd_close_tree_conn_fds(work);
ksmbd_tree_conn_disconnect(sess, tcon);
work->tcon = NULL;
return 0;
} }
/** /**
...@@ -2164,17 +2190,17 @@ int smb2_session_logoff(struct ksmbd_work *work) ...@@ -2164,17 +2190,17 @@ int smb2_session_logoff(struct ksmbd_work *work)
ksmbd_debug(SMB, "request\n"); ksmbd_debug(SMB, "request\n");
sess_id = le64_to_cpu(req->hdr.SessionId); ksmbd_conn_lock(conn);
if (!ksmbd_conn_good(conn)) {
rsp->StructureSize = cpu_to_le16(4); ksmbd_conn_unlock(conn);
err = ksmbd_iov_pin_rsp(work, rsp, sizeof(struct smb2_logoff_rsp)); rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
if (err) {
rsp->hdr.Status = STATUS_INSUFFICIENT_RESOURCES;
smb2_set_err_rsp(work); smb2_set_err_rsp(work);
return err; return -ENOENT;
} }
sess_id = le64_to_cpu(req->hdr.SessionId);
ksmbd_all_conn_set_status(sess_id, KSMBD_SESS_NEED_RECONNECT); ksmbd_all_conn_set_status(sess_id, KSMBD_SESS_NEED_RECONNECT);
ksmbd_conn_unlock(conn);
ksmbd_close_session_fds(work); ksmbd_close_session_fds(work);
ksmbd_conn_wait_idle(conn, sess_id); ksmbd_conn_wait_idle(conn, sess_id);
...@@ -2196,6 +2222,14 @@ int smb2_session_logoff(struct ksmbd_work *work) ...@@ -2196,6 +2222,14 @@ int smb2_session_logoff(struct ksmbd_work *work)
ksmbd_free_user(sess->user); ksmbd_free_user(sess->user);
sess->user = NULL; sess->user = NULL;
ksmbd_all_conn_set_status(sess_id, KSMBD_SESS_NEED_NEGOTIATE); ksmbd_all_conn_set_status(sess_id, KSMBD_SESS_NEED_NEGOTIATE);
rsp->StructureSize = cpu_to_le16(4);
err = ksmbd_iov_pin_rsp(work, rsp, sizeof(struct smb2_logoff_rsp));
if (err) {
rsp->hdr.Status = STATUS_INSUFFICIENT_RESOURCES;
smb2_set_err_rsp(work);
return err;
}
return 0; return 0;
} }
...@@ -3370,8 +3404,10 @@ int smb2_open(struct ksmbd_work *work) ...@@ -3370,8 +3404,10 @@ int smb2_open(struct ksmbd_work *work)
} }
ksmbd_revert_fsids(work); ksmbd_revert_fsids(work);
err_out1: err_out1:
if (!rc) if (!rc) {
ksmbd_update_fstate(&work->sess->file_table, fp, FP_INITED);
rc = ksmbd_iov_pin_rsp(work, (void *)rsp, iov_len); rc = ksmbd_iov_pin_rsp(work, (void *)rsp, iov_len);
}
if (rc) { if (rc) {
if (rc == -EINVAL) if (rc == -EINVAL)
rsp->hdr.Status = STATUS_INVALID_PARAMETER; rsp->hdr.Status = STATUS_INVALID_PARAMETER;
...@@ -7028,10 +7064,6 @@ int smb2_lock(struct ksmbd_work *work) ...@@ -7028,10 +7064,6 @@ int smb2_lock(struct ksmbd_work *work)
ksmbd_debug(SMB, ksmbd_debug(SMB,
"would have to wait for getting lock\n"); "would have to wait for getting lock\n");
spin_lock(&work->conn->llist_lock);
list_add_tail(&smb_lock->clist,
&work->conn->lock_list);
spin_unlock(&work->conn->llist_lock);
list_add(&smb_lock->llist, &rollback_list); list_add(&smb_lock->llist, &rollback_list);
argv = kmalloc(sizeof(void *), GFP_KERNEL); argv = kmalloc(sizeof(void *), GFP_KERNEL);
...@@ -7062,9 +7094,6 @@ int smb2_lock(struct ksmbd_work *work) ...@@ -7062,9 +7094,6 @@ int smb2_lock(struct ksmbd_work *work)
if (work->state != KSMBD_WORK_ACTIVE) { if (work->state != KSMBD_WORK_ACTIVE) {
list_del(&smb_lock->llist); list_del(&smb_lock->llist);
spin_lock(&work->conn->llist_lock);
list_del(&smb_lock->clist);
spin_unlock(&work->conn->llist_lock);
locks_free_lock(flock); locks_free_lock(flock);
if (work->state == KSMBD_WORK_CANCELLED) { if (work->state == KSMBD_WORK_CANCELLED) {
...@@ -7084,19 +7113,16 @@ int smb2_lock(struct ksmbd_work *work) ...@@ -7084,19 +7113,16 @@ int smb2_lock(struct ksmbd_work *work)
} }
list_del(&smb_lock->llist); list_del(&smb_lock->llist);
spin_lock(&work->conn->llist_lock);
list_del(&smb_lock->clist);
spin_unlock(&work->conn->llist_lock);
release_async_work(work); release_async_work(work);
goto retry; goto retry;
} else if (!rc) { } else if (!rc) {
list_add(&smb_lock->llist, &rollback_list);
spin_lock(&work->conn->llist_lock); spin_lock(&work->conn->llist_lock);
list_add_tail(&smb_lock->clist, list_add_tail(&smb_lock->clist,
&work->conn->lock_list); &work->conn->lock_list);
list_add_tail(&smb_lock->flist, list_add_tail(&smb_lock->flist,
&fp->lock_list); &fp->lock_list);
spin_unlock(&work->conn->llist_lock); spin_unlock(&work->conn->llist_lock);
list_add(&smb_lock->llist, &rollback_list);
ksmbd_debug(SMB, "successful in taking lock\n"); ksmbd_debug(SMB, "successful in taking lock\n");
} else { } else {
goto out; goto out;
...@@ -8036,10 +8062,10 @@ static void smb20_oplock_break_ack(struct ksmbd_work *work) ...@@ -8036,10 +8062,10 @@ static void smb20_oplock_break_ack(struct ksmbd_work *work)
goto err_out; goto err_out;
} }
opinfo_put(opinfo);
ksmbd_fd_put(work, fp);
opinfo->op_state = OPLOCK_STATE_NONE; opinfo->op_state = OPLOCK_STATE_NONE;
wake_up_interruptible_all(&opinfo->oplock_q); wake_up_interruptible_all(&opinfo->oplock_q);
opinfo_put(opinfo);
ksmbd_fd_put(work, fp);
rsp->StructureSize = cpu_to_le16(24); rsp->StructureSize = cpu_to_le16(24);
rsp->OplockLevel = rsp_oplevel; rsp->OplockLevel = rsp_oplevel;
......
...@@ -333,6 +333,9 @@ static void __ksmbd_close_fd(struct ksmbd_file_table *ft, struct ksmbd_file *fp) ...@@ -333,6 +333,9 @@ static void __ksmbd_close_fd(struct ksmbd_file_table *ft, struct ksmbd_file *fp)
static struct ksmbd_file *ksmbd_fp_get(struct ksmbd_file *fp) static struct ksmbd_file *ksmbd_fp_get(struct ksmbd_file *fp)
{ {
if (fp->f_state != FP_INITED)
return NULL;
if (!atomic_inc_not_zero(&fp->refcount)) if (!atomic_inc_not_zero(&fp->refcount))
return NULL; return NULL;
return fp; return fp;
...@@ -382,15 +385,20 @@ int ksmbd_close_fd(struct ksmbd_work *work, u64 id) ...@@ -382,15 +385,20 @@ int ksmbd_close_fd(struct ksmbd_work *work, u64 id)
return 0; return 0;
ft = &work->sess->file_table; ft = &work->sess->file_table;
read_lock(&ft->lock); write_lock(&ft->lock);
fp = idr_find(ft->idr, id); fp = idr_find(ft->idr, id);
if (fp) { if (fp) {
set_close_state_blocked_works(fp); set_close_state_blocked_works(fp);
if (!atomic_dec_and_test(&fp->refcount)) if (fp->f_state != FP_INITED)
fp = NULL; fp = NULL;
else {
fp->f_state = FP_CLOSED;
if (!atomic_dec_and_test(&fp->refcount))
fp = NULL;
}
} }
read_unlock(&ft->lock); write_unlock(&ft->lock);
if (!fp) if (!fp)
return -EINVAL; return -EINVAL;
...@@ -570,6 +578,7 @@ struct ksmbd_file *ksmbd_open_fd(struct ksmbd_work *work, struct file *filp) ...@@ -570,6 +578,7 @@ struct ksmbd_file *ksmbd_open_fd(struct ksmbd_work *work, struct file *filp)
fp->tcon = work->tcon; fp->tcon = work->tcon;
fp->volatile_id = KSMBD_NO_FID; fp->volatile_id = KSMBD_NO_FID;
fp->persistent_id = KSMBD_NO_FID; fp->persistent_id = KSMBD_NO_FID;
fp->f_state = FP_NEW;
fp->f_ci = ksmbd_inode_get(fp); fp->f_ci = ksmbd_inode_get(fp);
if (!fp->f_ci) { if (!fp->f_ci) {
...@@ -591,6 +600,14 @@ struct ksmbd_file *ksmbd_open_fd(struct ksmbd_work *work, struct file *filp) ...@@ -591,6 +600,14 @@ struct ksmbd_file *ksmbd_open_fd(struct ksmbd_work *work, struct file *filp)
return ERR_PTR(ret); return ERR_PTR(ret);
} }
void ksmbd_update_fstate(struct ksmbd_file_table *ft, struct ksmbd_file *fp,
unsigned int state)
{
write_lock(&ft->lock);
fp->f_state = state;
write_unlock(&ft->lock);
}
static int static int
__close_file_table_ids(struct ksmbd_file_table *ft, __close_file_table_ids(struct ksmbd_file_table *ft,
struct ksmbd_tree_connect *tcon, struct ksmbd_tree_connect *tcon,
......
...@@ -60,6 +60,12 @@ struct ksmbd_inode { ...@@ -60,6 +60,12 @@ struct ksmbd_inode {
__le32 m_fattr; __le32 m_fattr;
}; };
enum {
FP_NEW = 0,
FP_INITED,
FP_CLOSED
};
struct ksmbd_file { struct ksmbd_file {
struct file *filp; struct file *filp;
u64 persistent_id; u64 persistent_id;
...@@ -98,6 +104,7 @@ struct ksmbd_file { ...@@ -98,6 +104,7 @@ struct ksmbd_file {
/* if ls is happening on directory, below is valid*/ /* if ls is happening on directory, below is valid*/
struct ksmbd_readdir_data readdir_data; struct ksmbd_readdir_data readdir_data;
int dot_dotdot[2]; int dot_dotdot[2];
unsigned int f_state;
}; };
static inline void set_ctx_actor(struct dir_context *ctx, static inline void set_ctx_actor(struct dir_context *ctx,
...@@ -142,6 +149,8 @@ int ksmbd_close_inode_fds(struct ksmbd_work *work, struct inode *inode); ...@@ -142,6 +149,8 @@ int ksmbd_close_inode_fds(struct ksmbd_work *work, struct inode *inode);
int ksmbd_init_global_file_table(void); int ksmbd_init_global_file_table(void);
void ksmbd_free_global_file_table(void); void ksmbd_free_global_file_table(void);
void ksmbd_set_fd_limit(unsigned long limit); void ksmbd_set_fd_limit(unsigned long limit);
void ksmbd_update_fstate(struct ksmbd_file_table *ft, struct ksmbd_file *fp,
unsigned int state);
/* /*
* INODE hash * INODE hash
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment