Skip to content

Commit

Permalink
ksmbd: override fsids for share path check
Browse files Browse the repository at this point in the history
Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
namjaejeon committed Aug 1, 2024
1 parent 0317b45 commit 99437d3
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
15 changes: 12 additions & 3 deletions mgmt/share_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "share_config.h"
#include "user_config.h"
#include "user_session.h"
#include "../connection.h"
#include "../transport_ipc.h"
#include "../misc.h"

Expand Down Expand Up @@ -120,12 +121,13 @@ static int parse_veto_list(struct ksmbd_share_config *share,
return 0;
}

static struct ksmbd_share_config *share_config_request(struct unicode_map *um,
static struct ksmbd_share_config *share_config_request(struct ksmbd_work *work,
const char *name)
{
struct ksmbd_share_config_response *resp;
struct ksmbd_share_config *share = NULL;
struct ksmbd_share_config *lookup;
struct unicode_map *um = work->conn->um;
int ret;

resp = ksmbd_ipc_share_config_request(name);
Expand Down Expand Up @@ -181,7 +183,14 @@ static struct ksmbd_share_config *share_config_request(struct unicode_map *um,
KSMBD_SHARE_CONFIG_VETO_LIST(resp),
resp->veto_list_sz);
if (!ret && share->path) {
if (__ksmbd_override_fsids(work, share)) {
kill_share(share);
share = NULL;
goto out;
}

ret = kern_path(share->path, 0, &share->vfs_path);
ksmbd_revert_fsids(work);
if (ret) {
ksmbd_debug(SMB, "failed to access '%s'\n",
share->path);
Expand Down Expand Up @@ -214,7 +223,7 @@ static struct ksmbd_share_config *share_config_request(struct unicode_map *um,
return share;
}

struct ksmbd_share_config *ksmbd_share_config_get(struct unicode_map *um,
struct ksmbd_share_config *ksmbd_share_config_get(struct ksmbd_work *work,
const char *name)
{
struct ksmbd_share_config *share;
Expand All @@ -227,7 +236,7 @@ struct ksmbd_share_config *ksmbd_share_config_get(struct unicode_map *um,

if (share)
return share;
return share_config_request(um, name);
return share_config_request(work, name);
}

bool ksmbd_share_veto_filename(struct ksmbd_share_config *share,
Expand Down
4 changes: 3 additions & 1 deletion mgmt/share_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <linux/path.h>
#include <linux/unicode.h>

struct ksmbd_work;

struct ksmbd_share_config {
char *name;
char *path;
Expand Down Expand Up @@ -68,7 +70,7 @@ static inline void ksmbd_share_config_put(struct ksmbd_share_config *share)
__ksmbd_share_config_put(share);
}

struct ksmbd_share_config *ksmbd_share_config_get(struct unicode_map *um,
struct ksmbd_share_config *ksmbd_share_config_get(struct ksmbd_work *work,
const char *name);
bool ksmbd_share_veto_filename(struct ksmbd_share_config *share,
const char *filename);
Expand Down
9 changes: 5 additions & 4 deletions mgmt/tree_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
#include "user_session.h"

struct ksmbd_tree_conn_status
ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess,
const char *share_name)
ksmbd_tree_conn_connect(struct ksmbd_work *work, const char *share_name)
{
struct ksmbd_tree_conn_status status = {-ENOENT, NULL};
struct ksmbd_tree_connect_response *resp = NULL;
struct ksmbd_share_config *sc;
struct ksmbd_tree_connect *tree_conn = NULL;
struct sockaddr *peer_addr;
struct ksmbd_conn *conn = work->conn;
struct ksmbd_session *sess = work->sess;
int ret;

sc = ksmbd_share_config_get(conn->um, share_name);
sc = ksmbd_share_config_get(work, share_name);
if (!sc)
return status;

Expand Down Expand Up @@ -61,7 +62,7 @@ ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess,
struct ksmbd_share_config *new_sc;

ksmbd_share_config_del(sc);
new_sc = ksmbd_share_config_get(conn->um, share_name);
new_sc = ksmbd_share_config_get(work, share_name);
if (!new_sc) {
pr_err("Failed to update stale share config\n");
status.ret = -ESTALE;
Expand Down
4 changes: 2 additions & 2 deletions mgmt/tree_connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
struct ksmbd_share_config;
struct ksmbd_user;
struct ksmbd_conn;
struct ksmbd_work;

enum {
TREE_NEW = 0,
Expand Down Expand Up @@ -50,8 +51,7 @@ static inline int test_tree_conn_flag(struct ksmbd_tree_connect *tree_conn,
struct ksmbd_session;

struct ksmbd_tree_conn_status
ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess,
const char *share_name);
ksmbd_tree_conn_connect(struct ksmbd_work *work, const char *share_name);
void ksmbd_tree_connect_put(struct ksmbd_tree_connect *tcon);

int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess,
Expand Down
2 changes: 1 addition & 1 deletion smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,7 @@ int smb2_tree_connect(struct ksmbd_work *work)
ksmbd_debug(SMB, "tree connect request for tree %s treename %s\n",
name, treename);

status = ksmbd_tree_conn_connect(conn, sess, name);
status = ksmbd_tree_conn_connect(work, name);
if (status.ret == KSMBD_TREE_CONN_STATUS_OK)
rsp->hdr.Id.SyncId.TreeId = cpu_to_le32(status.tree_conn->id);
else
Expand Down
9 changes: 7 additions & 2 deletions smb_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,10 @@ bool is_asterisk(char *p)
return p && p[0] == '*';
}

int ksmbd_override_fsids(struct ksmbd_work *work)
int __ksmbd_override_fsids(struct ksmbd_work *work,
struct ksmbd_share_config *share)
{
struct ksmbd_session *sess = work->sess;
struct ksmbd_share_config *share = work->tcon->share_conf;
struct cred *cred;
struct group_info *gi;
unsigned int uid;
Expand Down Expand Up @@ -820,6 +820,11 @@ int ksmbd_override_fsids(struct ksmbd_work *work)
return 0;
}

int ksmbd_override_fsids(struct ksmbd_work *work)
{
return __ksmbd_override_fsids(work, work->tcon->share_conf);
}

void ksmbd_revert_fsids(struct ksmbd_work *work)
{
const struct cred *cred;
Expand Down
2 changes: 2 additions & 0 deletions smb_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ int ksmbd_extract_shortname(struct ksmbd_conn *conn,
int ksmbd_smb_negotiate_common(struct ksmbd_work *work, unsigned int command);

int ksmbd_smb_check_shared_mode(struct file *filp, struct ksmbd_file *curr_fp);
int __ksmbd_override_fsids(struct ksmbd_work *work,
struct ksmbd_share_config *share);
int ksmbd_override_fsids(struct ksmbd_work *work);
void ksmbd_revert_fsids(struct ksmbd_work *work);

Expand Down

0 comments on commit 99437d3

Please sign in to comment.