From patchwork Sun Oct 6 10:00:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 13823715 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FF111EB36; Sun, 6 Oct 2024 10:01:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208869; cv=none; b=H2+fr4RBksew+lyxnSpffl0xL+agVMVFCFfn71ASWDB3BaN1wj05/EwCRBub2NrH1qahcAK+SnIfDdUx9MUvGrC2S192nUGe5EWrU0ieAsnl7nrSDGQ4cVtXU1MVl7EO6DsP2ZtGX5MUIfRxStINVSHiQkmD1F9tCP+8ceVqVeI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208869; c=relaxed/simple; bh=wQDjDxaOIJ2QMPx/RGAlRjXH23pYiR7J647kSjFOiiE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=H083Yd8gmfIFSUt2kErQrRczECD6VID3Np1TpMms5uomz4zg9xPTRGSAk/UkTIeCmihdo1Ja0gsbiJfUpyGwvQ59UWIpU49vptrKV3sVJ35GO9e9FG22d1t46bujY/k6yMa0hu3l2j5CBsA+F+YxaxeBn7mm2VNvgZqvwK8kix4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hfzw/tcK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hfzw/tcK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2BC7C4CEC5; Sun, 6 Oct 2024 10:01:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728208869; bh=wQDjDxaOIJ2QMPx/RGAlRjXH23pYiR7J647kSjFOiiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hfzw/tcK3yAJsl/IeGZnvchmujoxE4xQ3BXUiPW8JcEOpJ+SpDJA8h6NoYcr4Fbbd N2FY88m4QbpON2LAQMhfXu8Q+dH2igl3TZB59PjwejiBXhjp8BNYAW/v9S1+Pg2EP3 OMxM1MufwWag/Y6mek27z9XL3clJrsgjWRMGpH2qRb/Ev/0rm++6LQX0Qdng4iVRIn PFwDyveytjyfmB4mePk80INfW6ygDlWY11gb6m3iZFqdnvXDI6m/0JXM7QcWfzJVvI XiAR47AsnPnWwOMnu+TExpr0aJ0vscA3w+oUoNgPHN3m/jhfBcKICoIXtkRwegiBPA z82zZMAolNAAg== Received: by pali.im (Postfix) id 2D481B49; Sun, 6 Oct 2024 12:01:02 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/7] cifs: Add mount option -o reparse=native Date: Sun, 6 Oct 2024 12:00:40 +0200 Message-Id: <20241006100046.30772-2-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241006100046.30772-1-pali@kernel.org> References: <20241006100046.30772-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently the default option is -o reparse=default which is same as -o reparse=nfs. Currently mount option -o reparse=nfs does not create symlink in NFS reparse point style, which is misleading. Add new -o reparse= options "native", "native+nfs" and "native+wsl" to make it more clear and allow to choose the expected reparse point types. "native" would mean to create new special files only with reparse point tags which are natively supported by SMB or Windows. Types which are not natively supported cannot be created. "native+nfs" would mean same as native, but fallback to "nfs" for unsupported types. "native+wsl" would mean to fallback to "wsl". Change also meaning of "nfs" and "wsl" to always create special types with nfs / wsl style. And change also the default option to "native+nfs", so the default behavior stay same as without this change. Without this change were all symlinks created in native Windows/SMB form and this stay same with this change too. Signed-off-by: Pali Rohár --- fs/smb/client/cifsglob.h | 15 ++++++++-- fs/smb/client/fs_context.c | 12 ++++++++ fs/smb/client/fs_context.h | 3 ++ fs/smb/client/reparse.c | 58 +++++++++++++++++++++++++++++++------- fs/smb/client/reparse.h | 2 ++ 5 files changed, 77 insertions(+), 13 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 260b553283ef..367f0ac6400d 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -154,14 +154,23 @@ enum securityEnum { }; enum cifs_reparse_type { - CIFS_REPARSE_TYPE_NFS, - CIFS_REPARSE_TYPE_WSL, - CIFS_REPARSE_TYPE_DEFAULT = CIFS_REPARSE_TYPE_NFS, + CIFS_REPARSE_TYPE_NATIVE, /* native symlinks only */ + CIFS_REPARSE_TYPE_NATIVE_NFS, /* native for symlinks, nfs for others */ + CIFS_REPARSE_TYPE_NATIVE_WSL, /* native for symlinks, wsl for others */ + CIFS_REPARSE_TYPE_NFS, /* nfs for everything */ + CIFS_REPARSE_TYPE_WSL, /* wsl for everything */ + CIFS_REPARSE_TYPE_DEFAULT = CIFS_REPARSE_TYPE_NATIVE_NFS, }; static inline const char *cifs_reparse_type_str(enum cifs_reparse_type type) { switch (type) { + case CIFS_REPARSE_TYPE_NATIVE: + return "native"; + case CIFS_REPARSE_TYPE_NATIVE_NFS: + return "native+nfs"; + case CIFS_REPARSE_TYPE_NATIVE_WSL: + return "native+wsl"; case CIFS_REPARSE_TYPE_NFS: return "nfs"; case CIFS_REPARSE_TYPE_WSL: diff --git a/fs/smb/client/fs_context.c b/fs/smb/client/fs_context.c index 22b550860cc8..e5de84912e3d 100644 --- a/fs/smb/client/fs_context.c +++ b/fs/smb/client/fs_context.c @@ -303,6 +303,9 @@ cifs_parse_cache_flavor(struct fs_context *fc, char *value, struct smb3_fs_conte static const match_table_t reparse_flavor_tokens = { { Opt_reparse_default, "default" }, + { Opt_reparse_native, "native" }, + { Opt_reparse_native_nfs, "native+nfs" }, + { Opt_reparse_native_wsl, "native+wsl" }, { Opt_reparse_nfs, "nfs" }, { Opt_reparse_wsl, "wsl" }, { Opt_reparse_err, NULL }, @@ -317,6 +320,15 @@ static int parse_reparse_flavor(struct fs_context *fc, char *value, case Opt_reparse_default: ctx->reparse_type = CIFS_REPARSE_TYPE_DEFAULT; break; + case Opt_reparse_native: + ctx->reparse_type = CIFS_REPARSE_TYPE_NATIVE; + break; + case Opt_reparse_native_nfs: + ctx->reparse_type = CIFS_REPARSE_TYPE_NATIVE_NFS; + break; + case Opt_reparse_native_wsl: + ctx->reparse_type = CIFS_REPARSE_TYPE_NATIVE_WSL; + break; case Opt_reparse_nfs: ctx->reparse_type = CIFS_REPARSE_TYPE_NFS; break; diff --git a/fs/smb/client/fs_context.h b/fs/smb/client/fs_context.h index 8dd12498ffd8..1011176ba3b7 100644 --- a/fs/smb/client/fs_context.h +++ b/fs/smb/client/fs_context.h @@ -43,6 +43,9 @@ enum { enum cifs_reparse_parm { Opt_reparse_default, + Opt_reparse_native, + Opt_reparse_native_nfs, + Opt_reparse_native_wsl, Opt_reparse_nfs, Opt_reparse_wsl, Opt_reparse_err diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index 6e9d914bac41..38fe0a710c65 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -14,6 +14,20 @@ #include "fs_context.h" #include "reparse.h" +static int mknod_nfs(unsigned int xid, struct inode *inode, + struct dentry *dentry, struct cifs_tcon *tcon, + const char *full_path, umode_t mode, dev_t dev, + const char *symname); + +static int mknod_wsl(unsigned int xid, struct inode *inode, + struct dentry *dentry, struct cifs_tcon *tcon, + const char *full_path, umode_t mode, dev_t dev, + const char *symname); + +static int create_native_symlink(const unsigned int xid, struct inode *inode, + struct dentry *dentry, struct cifs_tcon *tcon, + const char *full_path, const char *symname); + static int detect_directory_symlink_target(struct cifs_sb_info *cifs_sb, const unsigned int xid, const char *full_path, @@ -23,6 +37,26 @@ static int detect_directory_symlink_target(struct cifs_sb_info *cifs_sb, int smb2_create_reparse_symlink(const unsigned int xid, struct inode *inode, struct dentry *dentry, struct cifs_tcon *tcon, const char *full_path, const char *symname) +{ + struct smb3_fs_context *ctx = CIFS_SB(inode->i_sb)->ctx; + + switch (ctx->reparse_type) { + case CIFS_REPARSE_TYPE_NATIVE: + case CIFS_REPARSE_TYPE_NATIVE_NFS: + case CIFS_REPARSE_TYPE_NATIVE_WSL: + return create_native_symlink(xid, inode, dentry, tcon, full_path, symname); + case CIFS_REPARSE_TYPE_NFS: + return mknod_nfs(xid, inode, dentry, tcon, full_path, S_IFLNK, 0, symname); + case CIFS_REPARSE_TYPE_WSL: + return mknod_wsl(xid, inode, dentry, tcon, full_path, S_IFLNK, 0, symname); + default: + return -EOPNOTSUPP; + } +} + +static int create_native_symlink(const unsigned int xid, struct inode *inode, + struct dentry *dentry, struct cifs_tcon *tcon, + const char *full_path, const char *symname) { struct reparse_symlink_data_buffer *buf = NULL; struct cifs_open_info_data data = {}; @@ -363,6 +397,7 @@ static int nfs_set_reparse_buf(struct reparse_posix_data *buf, case NFS_SPECFILE_SOCK: dlen = 0; break; + case NFS_SPECFILE_LNK: /* TODO: add support for NFS symlinks */ default: return -EOPNOTSUPP; } @@ -381,7 +416,8 @@ static int nfs_set_reparse_buf(struct reparse_posix_data *buf, static int mknod_nfs(unsigned int xid, struct inode *inode, struct dentry *dentry, struct cifs_tcon *tcon, - const char *full_path, umode_t mode, dev_t dev) + const char *full_path, umode_t mode, dev_t dev, + const char *symname) { struct cifs_open_info_data data; struct reparse_posix_data *p; @@ -421,6 +457,7 @@ static int wsl_set_reparse_buf(struct reparse_data_buffer *buf, case IO_REPARSE_TAG_LX_FIFO: case IO_REPARSE_TAG_AF_UNIX: break; + case IO_REPARSE_TAG_LX_SYMLINK: /* TODO: add support for WSL symlinks */ default: return -EOPNOTSUPP; } @@ -518,7 +555,8 @@ static int wsl_set_xattrs(struct inode *inode, umode_t _mode, static int mknod_wsl(unsigned int xid, struct inode *inode, struct dentry *dentry, struct cifs_tcon *tcon, - const char *full_path, umode_t mode, dev_t dev) + const char *full_path, umode_t mode, dev_t dev, + const char *symname) { struct cifs_open_info_data data; struct reparse_data_buffer buf; @@ -563,17 +601,17 @@ int smb2_mknod_reparse(unsigned int xid, struct inode *inode, const char *full_path, umode_t mode, dev_t dev) { struct smb3_fs_context *ctx = CIFS_SB(inode->i_sb)->ctx; - int rc = -EOPNOTSUPP; switch (ctx->reparse_type) { + case CIFS_REPARSE_TYPE_NATIVE_NFS: case CIFS_REPARSE_TYPE_NFS: - rc = mknod_nfs(xid, inode, dentry, tcon, full_path, mode, dev); - break; + return mknod_nfs(xid, inode, dentry, tcon, full_path, mode, dev, NULL); + case CIFS_REPARSE_TYPE_NATIVE_WSL: case CIFS_REPARSE_TYPE_WSL: - rc = mknod_wsl(xid, inode, dentry, tcon, full_path, mode, dev); - break; + return mknod_wsl(xid, inode, dentry, tcon, full_path, mode, dev, NULL); + default: + return -EOPNOTSUPP; } - return rc; } /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */ @@ -848,7 +886,7 @@ int smb2_parse_native_symlink(char **target, const char *buf, unsigned int len, return rc; } -static int parse_reparse_symlink(struct reparse_symlink_data_buffer *sym, +static int parse_reparse_native_symlink(struct reparse_symlink_data_buffer *sym, u32 plen, bool unicode, struct cifs_sb_info *cifs_sb, const char *full_path, @@ -936,7 +974,7 @@ int parse_reparse_point(struct reparse_data_buffer *buf, return parse_reparse_posix((struct reparse_posix_data *)buf, cifs_sb, data); case IO_REPARSE_TAG_SYMLINK: - return parse_reparse_symlink( + return parse_reparse_native_symlink( (struct reparse_symlink_data_buffer *)buf, plen, unicode, cifs_sb, full_path, data); case IO_REPARSE_TAG_LX_SYMLINK: diff --git a/fs/smb/client/reparse.h b/fs/smb/client/reparse.h index eb6854e65e08..a6bdf20ce1b0 100644 --- a/fs/smb/client/reparse.h +++ b/fs/smb/client/reparse.h @@ -61,6 +61,7 @@ static inline kgid_t wsl_make_kgid(struct cifs_sb_info *cifs_sb, static inline u64 reparse_mode_nfs_type(mode_t mode) { switch (mode & S_IFMT) { + case S_IFLNK: return NFS_SPECFILE_LNK; case S_IFBLK: return NFS_SPECFILE_BLK; case S_IFCHR: return NFS_SPECFILE_CHR; case S_IFIFO: return NFS_SPECFILE_FIFO; @@ -72,6 +73,7 @@ static inline u64 reparse_mode_nfs_type(mode_t mode) static inline u32 reparse_mode_wsl_tag(mode_t mode) { switch (mode & S_IFMT) { + case S_IFLNK: return IO_REPARSE_TAG_LX_SYMLINK; case S_IFBLK: return IO_REPARSE_TAG_LX_BLK; case S_IFCHR: return IO_REPARSE_TAG_LX_CHR; case S_IFIFO: return IO_REPARSE_TAG_LX_FIFO; From patchwork Sun Oct 6 10:00:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 13823714 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FED3F4F1; Sun, 6 Oct 2024 10:01:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208869; cv=none; b=IlLCMIXxMGaR9uy2LbJH4soB74vaQVgu9BZLlGuSVNt26p2KWHy7HLwbs1TrXM7ZHlUOoD8WxcgjFW6GB1rvU2jLEVLI9iNa7owRQA6OJ6CBCXH94tXnsdhKiNAF3W0/BwRM+I2hAagz/sv9cCOFePfuFXkpVEBR+dn9FaJP368= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208869; c=relaxed/simple; bh=rM4fCOYDK4HI6B5oF+uWsvRWPszXfVkG2GCmWRKlU/I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Il/YNymoiUgixn/nmJK9D63QlfmM9JitObZqUx3N4hotVX/fllQDFAW0VFYgYokNQkhfPbJy1xCKJzPX/pkGg3N+qQzha77jwPBhcoFEhKr7SkuTrEi0cup1hOo4p/5TNS8+KZnUgOR1AvDo5mSrQHIp/iC7RhgzVT5PWA5v6Ds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WUTMWn0H; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WUTMWn0H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EAB8C4CECE; Sun, 6 Oct 2024 10:01:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728208869; bh=rM4fCOYDK4HI6B5oF+uWsvRWPszXfVkG2GCmWRKlU/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WUTMWn0HMXcXgLzcg8r939WIxmg+FiKbv+NJyiT7RSJd8QPUsKPYjjUeo+nVCDSZw Le/kw59rmTZ9s3niPxxrcBzgm61aMJywOG1RkWpvLVCr7/QlWmfW1QDMV6SMFsVqsa CNfQzINFKNwA9VZaGqxxnhz1EXDiWjyx8INkMVhFIkHEHDb7/IkAIEAQcsTTFPZIKe ab0IlG4YPXHeWoboaBNSgmjwi99sLYvr4cPD60+My1ILvcBYpWH1BzLDAOXxgSaPUP 2+MRoR5ofEtoJtNrEwKp+XWXP73KJ9/WXTVT89JhGIDpO33HDi+CU3u5tJFmY+oDLJ 3y1D2n64gcZbw== Received: by pali.im (Postfix) id 6B0A5BA4; Sun, 6 Oct 2024 12:01:02 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/7] cifs: Add mount option -o reparse=none Date: Sun, 6 Oct 2024 12:00:41 +0200 Message-Id: <20241006100046.30772-3-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241006100046.30772-1-pali@kernel.org> References: <20241006100046.30772-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This new mount option allows to completely disable creating new reparse points. When -o sfu or -o mfsymlinks is not specified then creating any special file (fifo, socket, symlink, block and char) will fail with -EOPNOTSUPP error. Signed-off-by: Pali Rohár --- fs/smb/client/cifsglob.h | 3 +++ fs/smb/client/fs_context.c | 4 ++++ fs/smb/client/fs_context.h | 1 + 3 files changed, 8 insertions(+) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 367f0ac6400d..7632d2ba5390 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -154,6 +154,7 @@ enum securityEnum { }; enum cifs_reparse_type { + CIFS_REPARSE_TYPE_NONE, /* disable creating new reparse points */ CIFS_REPARSE_TYPE_NATIVE, /* native symlinks only */ CIFS_REPARSE_TYPE_NATIVE_NFS, /* native for symlinks, nfs for others */ CIFS_REPARSE_TYPE_NATIVE_WSL, /* native for symlinks, wsl for others */ @@ -165,6 +166,8 @@ enum cifs_reparse_type { static inline const char *cifs_reparse_type_str(enum cifs_reparse_type type) { switch (type) { + case CIFS_REPARSE_TYPE_NONE: + return "none"; case CIFS_REPARSE_TYPE_NATIVE: return "native"; case CIFS_REPARSE_TYPE_NATIVE_NFS: diff --git a/fs/smb/client/fs_context.c b/fs/smb/client/fs_context.c index e5de84912e3d..3e402961cc95 100644 --- a/fs/smb/client/fs_context.c +++ b/fs/smb/client/fs_context.c @@ -303,6 +303,7 @@ cifs_parse_cache_flavor(struct fs_context *fc, char *value, struct smb3_fs_conte static const match_table_t reparse_flavor_tokens = { { Opt_reparse_default, "default" }, + { Opt_reparse_none, "none" }, { Opt_reparse_native, "native" }, { Opt_reparse_native_nfs, "native+nfs" }, { Opt_reparse_native_wsl, "native+wsl" }, @@ -320,6 +321,9 @@ static int parse_reparse_flavor(struct fs_context *fc, char *value, case Opt_reparse_default: ctx->reparse_type = CIFS_REPARSE_TYPE_DEFAULT; break; + case Opt_reparse_none: + ctx->reparse_type = CIFS_REPARSE_TYPE_NONE; + break; case Opt_reparse_native: ctx->reparse_type = CIFS_REPARSE_TYPE_NATIVE; break; diff --git a/fs/smb/client/fs_context.h b/fs/smb/client/fs_context.h index 1011176ba3b7..5db06de2ed35 100644 --- a/fs/smb/client/fs_context.h +++ b/fs/smb/client/fs_context.h @@ -43,6 +43,7 @@ enum { enum cifs_reparse_parm { Opt_reparse_default, + Opt_reparse_none, Opt_reparse_native, Opt_reparse_native_nfs, Opt_reparse_native_wsl, From patchwork Sun Oct 6 10:00:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 13823717 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A34B172BDE; Sun, 6 Oct 2024 10:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208870; cv=none; b=gMxVYfDVAeXf5i2jnpHvDSZxTAUBMpd0DN2dSo7OnYeIA5z2pVMqtt5YZZHcWgXpu56ZGsAYO1jePup0IUz0fHPKU7ThOjR+UIKTEN3Ba39ABlU2dETNcefEoTUh9XEPWU/sc/tAk8UVOjWU4hihKwG/5rBKI+Kdjiou/7jLTRQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208870; c=relaxed/simple; bh=1HEPHV7KcUkKxaUZCYCFRY2RNfcJW+87yTdK2jAscHM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=f7jbdRKe16s1JpaSNKi7POOD+n9Ib4XV8ypPnbcxFK8EF9F2NGlIXE5bG5u860yl+qCf8FaPKtJXXgZkOjHLf3fZXXdfYPbaiCX6b8Bql9dUNUInVwDyAVwUtdTIH8wdJAT5hpm/pVf16T1ce6SlB2PmjSc8Orxbm62uWRwba6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i7Ltkw6N; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i7Ltkw6N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D941C4CECF; Sun, 6 Oct 2024 10:01:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728208870; bh=1HEPHV7KcUkKxaUZCYCFRY2RNfcJW+87yTdK2jAscHM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i7Ltkw6NAfIP4tBmPRbL2iZ/OkcS+MF50wgcwpNjre7zVdy0yg0fdZPOiSJku2vYa Pjcn/gRq8XxSwD5rCxL2MzEXUC43t7SwC/YiTkL1nd6QC4iZ5iKncuMR75EuYJ7B82 hYixh8zSuq1Xnn69lfEFAJ4fApgmAs/IGrOgkRsz/FvyZK89fOvdx7SbzUBeN4S9G/ Mj3Jtc7PMXeEPLemy/NDU9ZrveVUG/JLar565uavtJKseaqvxAVNmJmdlB3zTyo9ww DU2LH/7GGY33qiVJXQZxgCDPVnMCqRw1DUDnZQuVTYBRf6mfBAnMvKVKQCl2ZVvrcJ ov28n6L1CyIHQ== Received: by pali.im (Postfix) id 9B4CBC2E; Sun, 6 Oct 2024 12:01:02 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/7] cifs: Add support for creating native Windows sockets Date: Sun, 6 Oct 2024 12:00:42 +0200 Message-Id: <20241006100046.30772-4-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241006100046.30772-1-pali@kernel.org> References: <20241006100046.30772-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Native Windows sockets created by WinSock on Windows 10 April 2018 Update (version 1803) or Windows Server 2019 (version 1809) or later versions is reparse point with IO_REPARSE_TAG_AF_UNIX tag, with empty reparse point data buffer and without any EAs. Create AF_UNIX sockets in this native format when -o reparse=native or -o reparse=native+ mount option is used. This change makes AF_UNIX sockets created by Linux CIFS client compatible with AF_UNIX sockets created by Windows applications on NTFS volumes. Signed-off-by: Pali Rohár --- fs/smb/client/cifsglob.h | 6 +++--- fs/smb/client/reparse.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 7632d2ba5390..570b22d02f7e 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -155,9 +155,9 @@ enum securityEnum { enum cifs_reparse_type { CIFS_REPARSE_TYPE_NONE, /* disable creating new reparse points */ - CIFS_REPARSE_TYPE_NATIVE, /* native symlinks only */ - CIFS_REPARSE_TYPE_NATIVE_NFS, /* native for symlinks, nfs for others */ - CIFS_REPARSE_TYPE_NATIVE_WSL, /* native for symlinks, wsl for others */ + CIFS_REPARSE_TYPE_NATIVE, /* native symlinks and sockets only, no support for others */ + CIFS_REPARSE_TYPE_NATIVE_NFS, /* native for symlinks/sockets, nfs for fifos/block/char */ + CIFS_REPARSE_TYPE_NATIVE_WSL, /* native for symlinks/sockets, wsl for fifos/block/char */ CIFS_REPARSE_TYPE_NFS, /* nfs for everything */ CIFS_REPARSE_TYPE_WSL, /* wsl for everything */ CIFS_REPARSE_TYPE_DEFAULT = CIFS_REPARSE_TYPE_NATIVE_NFS, diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index 38fe0a710c65..f1488f870320 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -379,6 +379,35 @@ static int detect_directory_symlink_target(struct cifs_sb_info *cifs_sb, return 0; } +static int create_native_socket(const unsigned int xid, struct inode *inode, + struct dentry *dentry, struct cifs_tcon *tcon, + const char *full_path) +{ + struct cifs_open_info_data data = { + .reparse_point = true, + .reparse = { .tag = IO_REPARSE_TAG_AF_UNIX, }, + }; + struct reparse_data_buffer buf = { + .ReparseTag = cpu_to_le32(IO_REPARSE_TAG_AF_UNIX), + .ReparseDataLength = 0, + }; + struct kvec iov = { + .iov_base = &buf, + .iov_len = sizeof(buf), + }; + struct inode *new; + int rc; + + new = smb2_get_reparse_inode(&data, inode->i_sb, xid, + tcon, full_path, false, &iov, NULL); + if (!IS_ERR(new)) + d_instantiate(dentry, new); + else + rc = PTR_ERR(new); + cifs_free_open_info(&data); + return rc; +} + static int nfs_set_reparse_buf(struct reparse_posix_data *buf, mode_t mode, dev_t dev, struct kvec *iov) @@ -602,6 +631,13 @@ int smb2_mknod_reparse(unsigned int xid, struct inode *inode, { struct smb3_fs_context *ctx = CIFS_SB(inode->i_sb)->ctx; + if (S_ISSOCK(mode) && ( + ctx->reparse_type == CIFS_REPARSE_TYPE_NATIVE || + ctx->reparse_type == CIFS_REPARSE_TYPE_NATIVE_NFS || + ctx->reparse_type == CIFS_REPARSE_TYPE_NATIVE_WSL)) { + return create_native_socket(xid, inode, dentry, tcon, full_path); + } + switch (ctx->reparse_type) { case CIFS_REPARSE_TYPE_NATIVE_NFS: case CIFS_REPARSE_TYPE_NFS: From patchwork Sun Oct 6 10:00:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 13823721 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59D5C17839E; Sun, 6 Oct 2024 10:01:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208873; cv=none; b=elwDZ+OxfotexymjiGIbeqZGRp+RAvmFwMIaIsdLwl+JkELbfPnhU5TSzu/CjpVW4OVQ4TFAY2RIZrPdGoVySZTYAAMhdprRfJ9ZMS5xB1rESOOP6nbXr6WFl8hlbTwO9JVipvNPBTinwjJ/T6GxOKjgvzZldG8ZYi+j9dW+qiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208873; c=relaxed/simple; bh=kOEasaYZhqGKSFx9kxpk6Zl3ATmAw3rrmXbQDYZOl90=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=emqvmY0+j5aT/QE2LrYWUoPYOf3/8g8MuSKv/wfvp9gbJiT6ZiCgPTGGHg71DV1t5+KMEaw6HCPmuWR3C0WBXETeHsSvosEUceosYr1aJeXlKvtnPJ3bVgj1XUBvp6ymgODIE6ExKNc5c9S8eq4aO6D2bs0SCTtDJdwQ0jZJfJ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VlxGLgFY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VlxGLgFY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E980C4CEC5; Sun, 6 Oct 2024 10:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728208872; bh=kOEasaYZhqGKSFx9kxpk6Zl3ATmAw3rrmXbQDYZOl90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VlxGLgFY/LxlnoWpD8k6vPI0CvZBEebvwDUYYlidbU/BHWT4tZJfN4E43eU07/V9f ldRt+YxKNyEdf/t/Ui635qwIGj1eCTigWUMW6N107+grJxxSKb5gNJLhqs3n+uk+FX yJnRV4LzJK2hfguR115T+908prm903zEsrqt0Stel6Z/vim+QzYiX64nS3r7SOS3gK c1HTIzXFl60nl3SMXuQrUKL0XDHfwOvUWq92lHzh4EdgBbU6XLIQHQzgiEaG3jg3Vm FpN8n7FOXEQYkpmwFl0ZEQYahtQBZwl7vMj/qdZOuj1/tLbyZMO1bwKarRClhAs6jz wc+swRFi+tq2Q== Received: by pali.im (Postfix) id CECB5C84; Sun, 6 Oct 2024 12:01:02 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/7] cifs: Add support for creating NFS-style symlinks Date: Sun, 6 Oct 2024 12:00:43 +0200 Message-Id: <20241006100046.30772-5-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241006100046.30772-1-pali@kernel.org> References: <20241006100046.30772-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 CIFS client is currently able to parse NFS-style symlinks, but is not able to create them. This functionality is useful when the mounted SMB share is used also by Windows NFS server (on Windows Server 2012 or new). It allows interop of symlinks between SMB share mounted by Linux CIFS client and same export from Windows NFS server mounted by some NFS client. New symlinks would be created in NFS-style only in case the mount option -o reparse=nfs is specified, which is not by default. So default CIFS mounts are not affected by this change. Signed-off-by: Pali Rohár --- fs/smb/client/reparse.c | 47 ++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index f1488f870320..41f91613e7f2 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -410,6 +410,8 @@ static int create_native_socket(const unsigned int xid, struct inode *inode, static int nfs_set_reparse_buf(struct reparse_posix_data *buf, mode_t mode, dev_t dev, + __le16 *symname_utf16, + int symname_utf16_len, struct kvec *iov) { u64 type; @@ -420,13 +422,18 @@ static int nfs_set_reparse_buf(struct reparse_posix_data *buf, switch ((type = reparse_mode_nfs_type(mode))) { case NFS_SPECFILE_BLK: case NFS_SPECFILE_CHR: - dlen = sizeof(__le64); + dlen = 2 * sizeof(__le32); + ((__le32 *)buf->DataBuffer)[0] = MAJOR(dev); + ((__le32 *)buf->DataBuffer)[1] = MINOR(dev); + break; + case NFS_SPECFILE_LNK: + dlen = symname_utf16_len; + memcpy(buf->DataBuffer, symname_utf16, symname_utf16_len); break; case NFS_SPECFILE_FIFO: case NFS_SPECFILE_SOCK: dlen = 0; break; - case NFS_SPECFILE_LNK: /* TODO: add support for NFS symlinks */ default: return -EOPNOTSUPP; } @@ -436,8 +443,6 @@ static int nfs_set_reparse_buf(struct reparse_posix_data *buf, buf->InodeType = cpu_to_le64(type); buf->ReparseDataLength = cpu_to_le16(len + dlen - sizeof(struct reparse_data_buffer)); - *(__le64 *)buf->DataBuffer = cpu_to_le64(((u64)MINOR(dev) << 32) | - MAJOR(dev)); iov->iov_base = buf; iov->iov_len = len + dlen; return 0; @@ -448,21 +453,42 @@ static int mknod_nfs(unsigned int xid, struct inode *inode, const char *full_path, umode_t mode, dev_t dev, const char *symname) { + struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); struct cifs_open_info_data data; - struct reparse_posix_data *p; + struct reparse_posix_data *p = NULL; + __le16 *symname_utf16 = NULL; + int symname_utf16_len = 0; struct inode *new; struct kvec iov; __u8 buf[sizeof(*p) + sizeof(__le64)]; int rc; - p = (struct reparse_posix_data *)buf; - rc = nfs_set_reparse_buf(p, mode, dev, &iov); + if (S_ISLNK(mode)) { + symname_utf16 = cifs_strndup_to_utf16(symname, strlen(symname), + &symname_utf16_len, + cifs_sb->local_nls, + NO_MAP_UNI_RSVD); + if (!symname_utf16) { + rc = -ENOMEM; + goto out; + } + symname_utf16_len -= 2; /* symlink is without trailing wide-nul */ + p = kzalloc(sizeof(*p) + symname_utf16_len, GFP_KERNEL); + if (!p) { + rc = -ENOMEM; + goto out; + } + } else { + p = (struct reparse_posix_data *)buf; + } + rc = nfs_set_reparse_buf(p, mode, dev, symname_utf16, symname_utf16_len, &iov); if (rc) - return rc; + goto out; data = (struct cifs_open_info_data) { .reparse_point = true, .reparse = { .tag = IO_REPARSE_TAG_NFS, .posix = p, }, + .symlink_target = kstrdup(symname, GFP_KERNEL), }; new = smb2_get_reparse_inode(&data, inode->i_sb, xid, @@ -472,6 +498,11 @@ static int mknod_nfs(unsigned int xid, struct inode *inode, else rc = PTR_ERR(new); cifs_free_open_info(&data); +out: + if (S_ISLNK(mode)) { + kfree(symname_utf16); + kfree(p); + } return rc; } From patchwork Sun Oct 6 10:00:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 13823716 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B24C172BA8; Sun, 6 Oct 2024 10:01:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208870; cv=none; b=dvrohM/SJnnloxIa+W+cUXXq1st/BwAqVtrBew0tIt9qELJp19rLBlqSc5UYrLcZvw0xguV2R3gXCYgzNd/ypLXE7kLrQ67r/gnuZU/cIZSXFH7C845LFwjGYKZt6Imtz5kMZ0B2vW8avHmueiH2KqWiZ1FMZNFZh8xocUwy2pQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208870; c=relaxed/simple; bh=HMbT4/jYDStIkanL13c7g7bisXyK3wEpZjkJqmhvzLw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=KFi7RmkLQMmZ6NDbymb4XEK9HHrLhn7dlU1Z91dy8qG0DOQ0SNbQEDjlxfSQGNGpkZmDTKhnA6F3LlTJmNJekEjl4+7Vi2qFEPhMgr2bVwvz9x91Z14zmt+Jmn+VJM9arIMWWWEkbBWE/Hc4kZpQDMzHynrgL5/H/qDo0duHlUM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qr1k+gLM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qr1k+gLM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 997D1C4CECC; Sun, 6 Oct 2024 10:01:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728208869; bh=HMbT4/jYDStIkanL13c7g7bisXyK3wEpZjkJqmhvzLw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qr1k+gLMxJsSyBBdVQ6BwRimxblAur+F5lGs645TvzzU3i3HTawqe5UOcbcyoUzrS vpIQIS33b/s0fFJVB0YeNveeK0si9YE1Bt9k++SHI1ebN981VKv7LbgUunF63S/NcP VLhRHZDr9PYAmjW81Zh5Mtq22JRoV7iwMJUkyhr7DtRoRUZywbAwi5FV2rUyXdjpug Rf0rG1HGebDS/iIGxlrtBWUEhPPFJCrh3PgovpcDc6lcBVnhRtSYrZ/215ptTp+kJS jgtV5rGSAxgWPD70wlOfX3ptEzdmv4shazDA1AdhboeJ0yhFYR5A2l5nQmz/WJt5cf ylvE+Ly7q+5Vg== Received: by pali.im (Postfix) id 24473CB5; Sun, 6 Oct 2024 12:01:03 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/7] cifs: Improve guard for excluding $LXDEV xattr Date: Sun, 6 Oct 2024 12:00:44 +0200 Message-Id: <20241006100046.30772-6-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241006100046.30772-1-pali@kernel.org> References: <20241006100046.30772-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 $LXDEV xattr is for storing block/char device's major and minor number. Change guard which excludes storing $LXDEV xattr to explicitly filter everything except block and char device. Current guard is opposite, which is currently correct but is less-safe. This change is required for adding support for creating WSL-style symlinks as symlinks also do not use device's major and minor numbers. Signed-off-by: Pali Rohár --- fs/smb/client/reparse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index 41f91613e7f2..402eb568f466 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -578,8 +578,8 @@ static int wsl_set_xattrs(struct inode *inode, umode_t _mode, memset(iov, 0, sizeof(*iov)); - /* Exclude $LXDEV xattr for sockets and fifos */ - if (S_ISSOCK(_mode) || S_ISFIFO(_mode)) + /* Exclude $LXDEV xattr for non-device files */ + if (!S_ISBLK(_mode) && !S_ISCHR(_mode)) num_xattrs = ARRAY_SIZE(xattrs) - 1; else num_xattrs = ARRAY_SIZE(xattrs); From patchwork Sun Oct 6 10:00:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 13823718 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68411173331; Sun, 6 Oct 2024 10:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208870; cv=none; b=hGEidSNNzhvK52obAt9Ve8LcktORTatN1GIcTP57fl40wpkk2dRc4XSi8C8F8qjsuG9Mr7vjnxN2l+YnhL34DeoJ18qECxOCg+3ZefhtEwz7TrYZy0jlerFm3SPdQRR2BmIljwp/2dZc0CTsLvI+Q7+odQUcVrDc1Dl/u+aAHvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208870; c=relaxed/simple; bh=W6n5Jr77kjwOeKY8KnGZDlpMZFxE5WYz+WvM1VpLAzY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=lcKbGf6bNW18VaQXmaiY1nWCQQlvZTTCqBs18Zqox9jfEIO8N6KGFNYAbu4FTT5Z4Zt3YxtluLPAmyKnJwja5HpCypSRPYwL5/Nj11ZhU7NRCsQQ44Uq0ctidxk+vNJjP44qBDFVKdEqHTPZ40l9yqzleHH++0qdK/3Y+/kpmRU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lNNOTwKT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lNNOTwKT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2990C4CED2; Sun, 6 Oct 2024 10:01:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728208870; bh=W6n5Jr77kjwOeKY8KnGZDlpMZFxE5WYz+WvM1VpLAzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lNNOTwKT0bAcL2JTYDL9wCV2e4ZD9kDuEisPj6bmYxyv5hl/HzZni89atOmRPBWxx 7cCmME901Fdw8dBYjFPqVkHmHOp8k7abXD+XJg1zjJxPTLldTe6u0P6dOHisUkm45v WT3GBQoOhKBNyJMgxC5iM+eFnzhrkT00+l67zKxfqp7ANhjDJpTzR82X2jIUkwa4yF bd70lXIuHpvyR+FJkABipFQI/k50q8iXxAvOVW/qOdOnkBwT+Lx/mHkFIo2xlcpNPA PWeC5B2DoI7I7mY55JtVD1PC+cWpQC2u3PkMHRuLRnePI4HLdh6PJHeYuFg7GCfeJR Ic4ebWfvDPTGw== Received: by pali.im (Postfix) id 735E4D0E; Sun, 6 Oct 2024 12:01:03 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/7] cifs: Add support for creating WSL-style symlinks Date: Sun, 6 Oct 2024 12:00:45 +0200 Message-Id: <20241006100046.30772-7-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241006100046.30772-1-pali@kernel.org> References: <20241006100046.30772-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This change implements support for creating new symlink in WSL-style by Linux cifs client when -o reparse=wsl mount option is specified. WSL-style symlink uses reparse point with tag IO_REPARSE_TAG_LX_SYMLINK and symlink target location is stored in reparse buffer in UTF-8 encoding prefixed by 32-bit flags. Flags bits are unknown, but it was observed that WSL always sets flags to value 0x02000000. Do same in Linux cifs client. New symlinks would be created in WSL-style only in case the mount option -o reparse=wsl is specified, which is not by default. So default CIFS mounts are not affected by this change. Signed-off-by: Pali Rohár --- fs/smb/client/reparse.c | 65 +++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index 402eb568f466..6606c40487ae 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -506,9 +506,17 @@ static int mknod_nfs(unsigned int xid, struct inode *inode, return rc; } -static int wsl_set_reparse_buf(struct reparse_data_buffer *buf, - mode_t mode, struct kvec *iov) +static int wsl_set_reparse_buf(struct reparse_data_buffer **buf, + mode_t mode, const char *symname, + struct cifs_sb_info *cifs_sb, + struct kvec *iov) { + struct reparse_wsl_symlink_data_buffer *symlink_buf; + __le16 *symname_utf16; + int symname_utf16_len; + int symname_utf8_maxlen; + int symname_utf8_len; + size_t buf_len; u32 tag; switch ((tag = reparse_mode_wsl_tag(mode))) { @@ -516,17 +524,45 @@ static int wsl_set_reparse_buf(struct reparse_data_buffer *buf, case IO_REPARSE_TAG_LX_CHR: case IO_REPARSE_TAG_LX_FIFO: case IO_REPARSE_TAG_AF_UNIX: + buf_len = sizeof(struct reparse_data_buffer); + *buf = kzalloc(buf_len, GFP_KERNEL); + if (!*buf) + return -ENOMEM; + break; + case IO_REPARSE_TAG_LX_SYMLINK: + symname_utf16 = cifs_strndup_to_utf16(symname, strlen(symname), + &symname_utf16_len, + cifs_sb->local_nls, + NO_MAP_UNI_RSVD); + if (!symname_utf16) + return -ENOMEM; + symname_utf8_maxlen = symname_utf16_len/2*3; + symlink_buf = kzalloc(sizeof(struct reparse_wsl_symlink_data_buffer) + + symname_utf8_maxlen, GFP_KERNEL); + if (!symlink_buf) { + kfree(symname_utf16); + return -ENOMEM; + } + /* Flag 0x02000000 is unknown, but all wsl symlinks have this value */ + symlink_buf->Flags = cpu_to_le32(0x02000000); + /* PathBuffer is in UTF-8 but without trailing null-term byte */ + symname_utf8_len = utf16s_to_utf8s(symname_utf16, symname_utf16_len/2, + UTF16_LITTLE_ENDIAN, + symlink_buf->PathBuffer, + symname_utf8_maxlen); + *buf = (struct reparse_data_buffer *)symlink_buf; + buf_len = sizeof(struct reparse_wsl_symlink_data_buffer) + symname_utf8_len; + kfree(symname_utf16); break; - case IO_REPARSE_TAG_LX_SYMLINK: /* TODO: add support for WSL symlinks */ default: return -EOPNOTSUPP; } - buf->ReparseTag = cpu_to_le32(tag); - buf->Reserved = 0; - buf->ReparseDataLength = 0; - iov->iov_base = buf; - iov->iov_len = sizeof(*buf); + (*buf)->ReparseTag = cpu_to_le32(tag); + (*buf)->Reserved = 0; + (*buf)->ReparseDataLength = buf_len - sizeof(struct reparse_data_buffer); + iov->iov_base = *buf; + iov->iov_len = buf_len; return 0; } @@ -618,25 +654,29 @@ static int mknod_wsl(unsigned int xid, struct inode *inode, const char *full_path, umode_t mode, dev_t dev, const char *symname) { + struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); struct cifs_open_info_data data; - struct reparse_data_buffer buf; + struct reparse_data_buffer *buf; struct smb2_create_ea_ctx *cc; struct inode *new; unsigned int len; struct kvec reparse_iov, xattr_iov; int rc; - rc = wsl_set_reparse_buf(&buf, mode, &reparse_iov); + rc = wsl_set_reparse_buf(&buf, mode, symname, cifs_sb, &reparse_iov); if (rc) return rc; rc = wsl_set_xattrs(inode, mode, dev, &xattr_iov); - if (rc) + if (rc) { + kfree(buf); return rc; + } data = (struct cifs_open_info_data) { .reparse_point = true, - .reparse = { .tag = le32_to_cpu(buf.ReparseTag), .buf = &buf, }, + .reparse = { .tag = le32_to_cpu(buf->ReparseTag), .buf = buf, }, + .symlink_target = kstrdup(symname, GFP_KERNEL), }; cc = xattr_iov.iov_base; @@ -653,6 +693,7 @@ static int mknod_wsl(unsigned int xid, struct inode *inode, rc = PTR_ERR(new); cifs_free_open_info(&data); kfree(xattr_iov.iov_base); + kfree(buf); return rc; } From patchwork Sun Oct 6 10:00:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 13823720 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0798B176252; Sun, 6 Oct 2024 10:01:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208872; cv=none; b=LMrOBPR8muCTmqWx/wRyckIzSAOtOMJ6uIk0jgsQxTW6h6PSv6wofA1gIv+ECwTP+2xs0C6X4Y9M+LJvd70GzQbGNzOomWlgEj3hPSxWsmvb98/1gdY/hf3WowfUNTmRLYZQhCClyjXQSvR2JNGi32h92Hhj3DN2Nh10ahGVBxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728208872; c=relaxed/simple; bh=PIF7Qur/PKKm4DYKUr+wEds9pKd7tP/IVUfLASXkER8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=LPWw8g/N4VH9M+wH5XKdzTwfZChpXPqEhByeyaQU34LSIoGLgJ2vNpDd1WJx0NyeD/M9jxWmo+FYXoT2zT5el8bHRFCBr/jtaO07+swZ02kNuQHCamKMDQYujVRZJ/WySYWahPRfF1AP6Cqrm9PVtOxRZ62ikqzE6iJLPtpzHT8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RI0WFRem; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RI0WFRem" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9E04C4CEC5; Sun, 6 Oct 2024 10:01:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728208871; bh=PIF7Qur/PKKm4DYKUr+wEds9pKd7tP/IVUfLASXkER8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RI0WFRem1EE08HV/1Ez5hRPtdS6SoTzM3ACcespjztSYwh+BJop/JgwZ4ntF7RJ5u hA5qV7i2dP4vysQ3JMOojrB35G6JDTJWSF5EqdAVh6g3Y9KtrqY3nvfAwRz/YXCUp2 ML5TatWk2pJQi5V6ZZKG1+ZscXhkdwjYlqYRt1duXz3gS9ll0WW9yhGYvmcKerqsnf o8BThlokuw5OG3aaStENxHL1VhWavwItFd9t3n2RXRanx5ABoWX0FWxUxG7CEVUDVP C3aLgUAYT0O9wCpRSqqTXkpFgGzAUKbyj/INMNPsaNjiJa6m/BaPxXCYCLJeGp/ZHA T57MntVfRVJiQ== Received: by pali.im (Postfix) id 9FBA5DE8; Sun, 6 Oct 2024 12:01:03 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Steve French , Paulo Alcantara , Ronnie Sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/7] cifs: Validate content of WSL reparse point buffers Date: Sun, 6 Oct 2024 12:00:46 +0200 Message-Id: <20241006100046.30772-8-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241006100046.30772-1-pali@kernel.org> References: <20241006100046.30772-1-pali@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 WSL socket, fifo, char and block devices have empty reparse buffer. Validate the length of the reparse buffer. Signed-off-by: Pali Rohár --- fs/smb/client/reparse.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index 6606c40487ae..c0d9ba14a60d 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -1093,6 +1093,11 @@ int parse_reparse_point(struct reparse_data_buffer *buf, case IO_REPARSE_TAG_LX_FIFO: case IO_REPARSE_TAG_LX_CHR: case IO_REPARSE_TAG_LX_BLK: + if (le16_to_cpu(buf->ReparseDataLength) != 0) { + cifs_dbg(VFS, "srv returned malformed buffer for reparse point: 0x%08x\n", + le32_to_cpu(buf->ReparseTag)); + return -EIO; + } break; default: cifs_tcon_dbg(VFS | ONCE, "unhandled reparse tag: 0x%08x\n",