Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# Makefile for Linux filesystem routines that are shared by client and server.
#
obj-$(CONFIG_SMBFS) += cifs_md4.o
obj-$(CONFIG_SMBFS) += smb_compress.o
smb_compress-y := compress/compress.o compress/lz77.o
+198
View File
@@ -0,0 +1,198 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Cryptographic API.
*
* MD4 Message Digest Algorithm (RFC1320).
*
* Implementation derived from Andrew Tridgell and Steve French's
* CIFS MD4 implementation, and the cryptoapi implementation
* originally based on the public domain implementation written
* by Colin Plumb in 1993.
*
* Copyright (c) Andrew Tridgell 1997-1998.
* Modified by Steve French (sfrench@us.ibm.com) 2002
* Copyright (c) Cryptoapi developers.
* Copyright (c) 2002 David S. Miller (davem@redhat.com)
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
*
*/
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/types.h>
#include <asm/byteorder.h>
#include "md4.h"
MODULE_DESCRIPTION("MD4 Message Digest Algorithm (RFC1320)");
MODULE_LICENSE("GPL");
static inline u32 lshift(u32 x, unsigned int s)
{
x &= 0xFFFFFFFF;
return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s));
}
static inline u32 F(u32 x, u32 y, u32 z)
{
return (x & y) | ((~x) & z);
}
static inline u32 G(u32 x, u32 y, u32 z)
{
return (x & y) | (x & z) | (y & z);
}
static inline u32 H(u32 x, u32 y, u32 z)
{
return x ^ y ^ z;
}
#define ROUND1(a,b,c,d,k,s) (a = lshift(a + F(b,c,d) + k, s))
#define ROUND2(a,b,c,d,k,s) (a = lshift(a + G(b,c,d) + k + (u32)0x5A827999,s))
#define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (u32)0x6ED9EBA1,s))
static void md4_transform(u32 *hash, u32 const *in)
{
u32 a, b, c, d;
a = hash[0];
b = hash[1];
c = hash[2];
d = hash[3];
ROUND1(a, b, c, d, in[0], 3);
ROUND1(d, a, b, c, in[1], 7);
ROUND1(c, d, a, b, in[2], 11);
ROUND1(b, c, d, a, in[3], 19);
ROUND1(a, b, c, d, in[4], 3);
ROUND1(d, a, b, c, in[5], 7);
ROUND1(c, d, a, b, in[6], 11);
ROUND1(b, c, d, a, in[7], 19);
ROUND1(a, b, c, d, in[8], 3);
ROUND1(d, a, b, c, in[9], 7);
ROUND1(c, d, a, b, in[10], 11);
ROUND1(b, c, d, a, in[11], 19);
ROUND1(a, b, c, d, in[12], 3);
ROUND1(d, a, b, c, in[13], 7);
ROUND1(c, d, a, b, in[14], 11);
ROUND1(b, c, d, a, in[15], 19);
ROUND2(a, b, c, d, in[0], 3);
ROUND2(d, a, b, c, in[4], 5);
ROUND2(c, d, a, b, in[8], 9);
ROUND2(b, c, d, a, in[12], 13);
ROUND2(a, b, c, d, in[1], 3);
ROUND2(d, a, b, c, in[5], 5);
ROUND2(c, d, a, b, in[9], 9);
ROUND2(b, c, d, a, in[13], 13);
ROUND2(a, b, c, d, in[2], 3);
ROUND2(d, a, b, c, in[6], 5);
ROUND2(c, d, a, b, in[10], 9);
ROUND2(b, c, d, a, in[14], 13);
ROUND2(a, b, c, d, in[3], 3);
ROUND2(d, a, b, c, in[7], 5);
ROUND2(c, d, a, b, in[11], 9);
ROUND2(b, c, d, a, in[15], 13);
ROUND3(a, b, c, d, in[0], 3);
ROUND3(d, a, b, c, in[8], 9);
ROUND3(c, d, a, b, in[4], 11);
ROUND3(b, c, d, a, in[12], 15);
ROUND3(a, b, c, d, in[2], 3);
ROUND3(d, a, b, c, in[10], 9);
ROUND3(c, d, a, b, in[6], 11);
ROUND3(b, c, d, a, in[14], 15);
ROUND3(a, b, c, d, in[1], 3);
ROUND3(d, a, b, c, in[9], 9);
ROUND3(c, d, a, b, in[5], 11);
ROUND3(b, c, d, a, in[13], 15);
ROUND3(a, b, c, d, in[3], 3);
ROUND3(d, a, b, c, in[11], 9);
ROUND3(c, d, a, b, in[7], 11);
ROUND3(b, c, d, a, in[15], 15);
hash[0] += a;
hash[1] += b;
hash[2] += c;
hash[3] += d;
}
static inline void md4_transform_helper(struct md4_ctx *ctx)
{
le32_to_cpu_array(ctx->block, ARRAY_SIZE(ctx->block));
md4_transform(ctx->hash, ctx->block);
}
int cifs_md4_init(struct md4_ctx *mctx)
{
memset(mctx, 0, sizeof(struct md4_ctx));
mctx->hash[0] = 0x67452301;
mctx->hash[1] = 0xefcdab89;
mctx->hash[2] = 0x98badcfe;
mctx->hash[3] = 0x10325476;
mctx->byte_count = 0;
return 0;
}
EXPORT_SYMBOL_GPL(cifs_md4_init);
int cifs_md4_update(struct md4_ctx *mctx, const u8 *data, unsigned int len)
{
const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
mctx->byte_count += len;
if (avail > len) {
memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
data, len);
return 0;
}
memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
data, avail);
md4_transform_helper(mctx);
data += avail;
len -= avail;
while (len >= sizeof(mctx->block)) {
memcpy(mctx->block, data, sizeof(mctx->block));
md4_transform_helper(mctx);
data += sizeof(mctx->block);
len -= sizeof(mctx->block);
}
memcpy(mctx->block, data, len);
return 0;
}
EXPORT_SYMBOL_GPL(cifs_md4_update);
int cifs_md4_final(struct md4_ctx *mctx, u8 *out)
{
const unsigned int offset = mctx->byte_count & 0x3f;
char *p = (char *)mctx->block + offset;
int padding = 56 - (offset + 1);
*p++ = 0x80;
if (padding < 0) {
memset(p, 0x00, padding + sizeof(u64));
md4_transform_helper(mctx);
p = (char *)mctx->block;
padding = 56;
}
memset(p, 0, padding);
mctx->block[14] = mctx->byte_count << 3;
mctx->block[15] = mctx->byte_count >> 29;
le32_to_cpu_array(mctx->block, (sizeof(mctx->block) -
sizeof(u64)) / sizeof(u32));
md4_transform(mctx->hash, mctx->block);
cpu_to_le32_array(mctx->hash, ARRAY_SIZE(mctx->hash));
memcpy(out, mctx->hash, sizeof(mctx->hash));
memset(mctx, 0, sizeof(*mctx));
return 0;
}
EXPORT_SYMBOL_GPL(cifs_md4_final);
@@ -0,0 +1,404 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* SMB2 compression transform helpers.
*
* Copyright (C) 2026 Namjae Jeon <linkinjeon@kernel.org>
*/
#include <linux/module.h>
#include <linux/overflow.h>
#include <linux/string.h>
#include <linux/unaligned.h>
#include "compress.h"
#include "lz77.h"
#define SMB2_COMPRESSION_CHAINED_HDR_LEN \
offsetof(struct smb2_compression_hdr, CompressionAlgorithm)
#define SMB2_COMPRESSION_PAYLOAD_BASE_LEN \
(sizeof(struct smb2_compression_payload_hdr) - sizeof(__le32))
/*
* A NONE payload carries bytes verbatim. Keep both cursors and remaining
* lengths together so every chained payload handler applies identical bounds
* accounting.
*/
static int smb_decompress_none(const u8 **src, u32 *slen, u8 **dst, u32 *dlen,
u32 len)
{
if (len > *slen || len > *dlen)
return -EINVAL;
memcpy(*dst, *src, len);
*src += len;
*slen -= len;
*dst += len;
*dlen -= len;
return 0;
}
/*
* Pattern_V1 represents a run of one byte. Its wire payload is always the
* fixed-size smb2_compression_pattern_v1 structure.
*/
static int smb_decompress_pattern(const u8 **src, u32 *slen, u8 **dst,
u32 *dlen, u32 len)
{
const struct smb2_compression_pattern_v1 *pattern;
u32 repetitions;
if (len != sizeof(*pattern) || len > *slen)
return -EINVAL;
pattern = (const struct smb2_compression_pattern_v1 *)*src;
repetitions = le32_to_cpu(pattern->Repetitions);
if (repetitions > *dlen)
return -EINVAL;
memset(*dst, pattern->Pattern, repetitions);
*src += len;
*slen -= len;
*dst += repetitions;
*dlen -= repetitions;
return 0;
}
/*
* LZ77 payload Length includes the four-byte OriginalPayloadSize field.
* Consume that field before passing the compressed stream to the raw codec.
*/
static int smb_decompress_lz77_payload(const u8 **src, u32 *slen, u8 **dst,
u32 *dlen, u32 len)
{
u32 orig_size;
int rc;
if (len < sizeof(__le32) || len > *slen)
return -EINVAL;
orig_size = get_unaligned_le32(*src);
if (orig_size > *dlen)
return -EINVAL;
*src += sizeof(__le32);
*slen -= sizeof(__le32);
len -= sizeof(__le32);
rc = smb_lz77_decompress(*src, len, *dst, orig_size);
if (rc)
return rc;
*src += len;
*slen -= len;
*dst += orig_size;
*dlen -= orig_size;
return 0;
}
static int smb_decompress_chained(__le16 alg, bool allow_chained,
bool allow_pattern,
const struct smb2_compression_hdr *hdr,
u32 slen, void *dst, u32 dlen)
{
const struct smb2_compression_payload_hdr *payload;
const u8 *src = (const u8 *)hdr + SMB2_COMPRESSION_CHAINED_HDR_LEN;
u32 orig_size = le32_to_cpu(hdr->OriginalCompressedSegmentSize);
u32 remaining = slen - SMB2_COMPRESSION_CHAINED_HDR_LEN;
u8 *out = dst;
u32 out_remaining = dlen;
bool first = true;
int rc;
if (!allow_chained || orig_size != dlen)
return -EINVAL;
/*
* The chained transform has an eight-byte top-level header. The next
* bytes are a sequence of payload headers whose Length fields account
* for payload data, including OriginalPayloadSize where applicable.
*/
while (remaining) {
__le16 payload_alg;
__le16 flags;
u32 len;
if (remaining < SMB2_COMPRESSION_PAYLOAD_BASE_LEN)
return -EINVAL;
payload = (const struct smb2_compression_payload_hdr *)src;
payload_alg = payload->CompressionAlgorithm;
flags = payload->Flags;
len = le32_to_cpu(payload->Length);
/*
* CHAINED marks only the first payload. Requiring NONE on every
* later payload rejects ambiguous or independently chained data.
*/
if ((first && flags != cpu_to_le16(SMB2_COMPRESSION_FLAG_CHAINED)) ||
(!first && flags != cpu_to_le16(SMB2_COMPRESSION_FLAG_NONE)))
return -EINVAL;
src += SMB2_COMPRESSION_PAYLOAD_BASE_LEN;
remaining -= SMB2_COMPRESSION_PAYLOAD_BASE_LEN;
if (payload_alg == SMB3_COMPRESS_NONE) {
rc = smb_decompress_none(&src, &remaining, &out,
&out_remaining, len);
} else if (payload_alg == SMB3_COMPRESS_PATTERN) {
if (!allow_pattern)
return -EINVAL;
rc = smb_decompress_pattern(&src, &remaining, &out,
&out_remaining, len);
} else if (payload_alg == alg && alg == SMB3_COMPRESS_LZ77) {
rc = smb_decompress_lz77_payload(&src, &remaining, &out,
&out_remaining, len);
} else {
return -EINVAL;
}
if (rc)
return rc;
first = false;
}
return out_remaining ? -EINVAL : 0;
}
static int smb_decompress_unchained(__le16 alg,
const struct smb2_compression_hdr *hdr,
u32 slen, void *dst, u32 dlen)
{
u32 orig_size, offset, comp_size;
if (hdr->CompressionAlgorithm != alg ||
!smb_compress_alg_valid(hdr->CompressionAlgorithm, false))
return -EINVAL;
orig_size = le32_to_cpu(hdr->OriginalCompressedSegmentSize);
offset = le32_to_cpu(hdr->Offset);
if (offset > slen - sizeof(*hdr) || offset > dlen ||
orig_size > dlen - offset || orig_size + offset != dlen)
return -EINVAL;
memcpy(dst, (const u8 *)hdr + sizeof(*hdr), offset);
comp_size = slen - sizeof(*hdr) - offset;
return smb_lz77_decompress((const u8 *)hdr + sizeof(*hdr) + offset,
comp_size, (u8 *)dst + offset, orig_size);
}
/**
* smb_compression_decompress() - decode an SMB2 compression transform
* @alg: negotiated general-purpose compression algorithm
* @allow_chained: whether chained transforms were negotiated
* @allow_pattern: whether Pattern_V1 payloads were negotiated
* @src: transform header followed by compressed payload data
* @slen: total number of bytes available at @src
* @dst: output buffer for the reconstructed SMB2 message
* @dlen: exact expected size of the reconstructed SMB2 message
*
* Validate the transform type and negotiated capabilities before dispatching
* to the chained or unchained decoder. The caller supplies the expected output
* size after applying its transport-specific message size limits.
*
* Return: 0 on success, otherwise a negative errno.
*/
int smb_compression_decompress(__le16 alg, bool allow_chained,
bool allow_pattern, const void *src, u32 slen,
void *dst, u32 dlen)
{
const struct smb2_compression_hdr *hdr = src;
if (!src || !dst || slen < sizeof(*hdr) ||
hdr->ProtocolId != SMB2_COMPRESSION_TRANSFORM_ID ||
alg == SMB3_COMPRESS_NONE)
return -EINVAL;
if (hdr->Flags == cpu_to_le16(SMB2_COMPRESSION_FLAG_CHAINED))
return smb_decompress_chained(alg, allow_chained, allow_pattern,
hdr, slen, dst, dlen);
if (hdr->Flags != cpu_to_le16(SMB2_COMPRESSION_FLAG_NONE))
return -EINVAL;
return smb_decompress_unchained(alg, hdr, slen, dst, dlen);
}
EXPORT_SYMBOL_GPL(smb_compression_decompress);
struct smb_compression_builder {
u8 *pos;
u32 remaining;
bool first;
};
/*
* Reserve one chained payload header and initialize its common fields.
* OriginalPayloadSize is present only for LZNT1/LZ77/LZ77+Huffman payloads.
*/
static struct smb2_compression_payload_hdr *
smb_compression_add_payload(struct smb_compression_builder *builder,
__le16 alg, u32 payload_len, bool orig_size)
{
struct smb2_compression_payload_hdr *payload;
u32 hdr_len = SMB2_COMPRESSION_PAYLOAD_BASE_LEN;
u32 total_len;
if (orig_size)
hdr_len += sizeof(payload->OriginalPayloadSize);
if (check_add_overflow(hdr_len, payload_len, &total_len) ||
total_len > builder->remaining)
return NULL;
payload = (struct smb2_compression_payload_hdr *)builder->pos;
payload->CompressionAlgorithm = alg;
payload->Flags = cpu_to_le16(builder->first ?
SMB2_COMPRESSION_FLAG_CHAINED : SMB2_COMPRESSION_FLAG_NONE);
payload->Length = cpu_to_le32(payload_len +
(orig_size ? sizeof(payload->OriginalPayloadSize) : 0));
builder->pos += hdr_len;
builder->remaining -= hdr_len;
builder->first = false;
return payload;
}
static int smb_compression_add_pattern(struct smb_compression_builder *builder,
u8 pattern, u32 repetitions)
{
struct smb2_compression_pattern_v1 *payload;
if (!smb_compression_add_payload(builder, SMB3_COMPRESS_PATTERN,
sizeof(*payload), false))
return -ENOSPC;
payload = (struct smb2_compression_pattern_v1 *)builder->pos;
payload->Pattern = pattern;
payload->Reserved1 = 0;
payload->Reserved2 = 0;
payload->Repetitions = cpu_to_le32(repetitions);
builder->pos += sizeof(*payload);
builder->remaining -= sizeof(*payload);
return 0;
}
static int smb_compression_add_none(struct smb_compression_builder *builder,
const u8 *src, u32 len)
{
if (!smb_compression_add_payload(builder, SMB3_COMPRESS_NONE, len, false))
return -ENOSPC;
memcpy(builder->pos, src, len);
builder->pos += len;
builder->remaining -= len;
return 0;
}
static int smb_compression_add_lz77(struct smb_compression_builder *builder,
const u8 *src, u32 len)
{
struct smb2_compression_payload_hdr *payload;
u32 comp_len;
int rc;
if (builder->remaining <= sizeof(*payload))
return -ENOSPC;
comp_len = builder->remaining - sizeof(*payload);
payload = smb_compression_add_payload(builder, SMB3_COMPRESS_LZ77,
comp_len, true);
if (!payload)
return -ENOSPC;
rc = smb_lz77_compress(src, len, builder->pos, &comp_len);
if (rc)
return rc;
payload->Length = cpu_to_le32(comp_len +
sizeof(payload->OriginalPayloadSize));
payload->OriginalPayloadSize = cpu_to_le32(len);
builder->pos += comp_len;
builder->remaining -= comp_len;
return 0;
}
/**
* smb_compression_compress_chained() - build a chained SMB2 transform
* @alg: negotiated general-purpose compression algorithm
* @allow_pattern: whether Pattern_V1 was negotiated
* @src: complete uncompressed SMB2 message
* @slen: size of @src
* @dst: output buffer for the transform
* @dlen: input capacity of @dst and output transform size
*
* Following the algorithm in [MS-SMB2] 3.1.4.4, encode sufficiently long
* repeated runs at the front and back as Pattern_V1 payloads. Compress a
* middle region larger than 1 KiB with LZ77; smaller middle regions are
* represented by a chained NONE payload.
*
* This helper does not decide whether the final transform is smaller than the
* original message. The transport caller owns that policy decision.
*
* Return: 0 on success, otherwise a negative errno.
*/
int smb_compression_compress_chained(__le16 alg, bool allow_pattern,
const void *src, u32 slen,
void *dst, u32 *dlen)
{
struct smb2_compression_hdr *hdr = dst;
struct smb_compression_builder builder;
const u8 *input = src;
u32 forward = 0, backward = 0, middle_len;
int rc;
if (!src || !dst || !dlen || alg != SMB3_COMPRESS_LZ77 ||
*dlen <= SMB2_COMPRESSION_CHAINED_HDR_LEN || !slen)
return -EINVAL;
hdr->ProtocolId = SMB2_COMPRESSION_TRANSFORM_ID;
hdr->OriginalCompressedSegmentSize = cpu_to_le32(slen);
builder.pos = (u8 *)dst + SMB2_COMPRESSION_CHAINED_HDR_LEN;
builder.remaining = *dlen - SMB2_COMPRESSION_CHAINED_HDR_LEN;
builder.first = true;
if (allow_pattern && slen > 32) {
for (forward = 1; forward < slen; forward++) {
if (input[forward] != input[0])
break;
}
if (forward <= 32)
forward = 0;
for (backward = 1; backward < slen - forward; backward++) {
if (input[slen - backward - 1] != input[slen - 1])
break;
}
if (backward <= 32)
backward = 0;
}
if (forward) {
rc = smb_compression_add_pattern(&builder, input[0], forward);
if (rc)
return rc;
}
middle_len = slen - forward - backward;
if (middle_len > 1024)
rc = smb_compression_add_lz77(&builder, input + forward,
middle_len);
else if (middle_len)
rc = smb_compression_add_none(&builder,
input + forward, middle_len);
else
rc = 0;
if (rc)
return rc;
if (backward) {
rc = smb_compression_add_pattern(&builder, input[slen - 1],
backward);
if (rc)
return rc;
}
*dlen = builder.pos - (u8 *)dst;
return 0;
}
EXPORT_SYMBOL_GPL(smb_compression_compress_chained);
@@ -0,0 +1,29 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (C) 2026 Namjae Jeon <linkinjeon@kernel.org>
*/
#ifndef _COMMON_SMB_COMPRESS_H
#define _COMMON_SMB_COMPRESS_H
#include "../smb2pdu.h"
/*
* SMB3_COMPRESS_NONE is valid only in chained payload headers. It is never
* negotiated as a compression algorithm.
*/
static __always_inline bool smb_compress_alg_valid(__le16 alg, bool valid_none)
{
if (alg == SMB3_COMPRESS_NONE)
return valid_none;
return alg == SMB3_COMPRESS_LZ77 || alg == SMB3_COMPRESS_PATTERN;
}
int smb_compression_decompress(__le16 alg, bool allow_chained,
bool allow_pattern, const void *src, u32 slen,
void *dst, u32 dlen);
int smb_compression_compress_chained(__le16 alg, bool allow_pattern,
const void *src, u32 slen,
void *dst, u32 *dlen);
#endif /* _COMMON_SMB_COMPRESS_H */
+461
View File
@@ -0,0 +1,461 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2024-2026, SUSE LLC
* Copyright (C) 2026 Namjae Jeon <linkinjeon@kernel.org>
*
* Authors: Enzo Matsumiya <ematsumiya@suse.de>
* Namjae Jeon <linkinjeon@kernel.org>
*
* Implementation of the LZ77 "plain" compression algorithm, as per MS-XCA spec.
*/
#include <linux/slab.h>
#include <linux/sizes.h>
#include <linux/count_zeros.h>
#include <linux/unaligned.h>
#include <linux/module.h>
#include <linux/overflow.h>
#include "lz77.h"
/*
* Compression parameters.
*
* LZ77_MATCH_MAX_DIST: Farthest back a match can be from current position (can be 1 - 8K).
* LZ77_HASH_LOG:
* LZ77_HASH_SIZE: ilog2 hash size (recommended to be 13 - 18, default 15 (hash size
* 32k)).
* LZ77_RSTEP_SIZE: Number of bytes to read from input buffer for hashing and initial
* match check (default 4 bytes, this effectivelly makes this the min
* match len).
* LZ77_MSTEP_SIZE: Number of bytes to extend-compare a found match (default 8 bytes).
* LZ77_SKIP_TRIGGER: ilog2 value for adaptive skipping, i.e. to progressively skip input
* bytes when we can't find matches. Default is 4.
* Higher values (>0) will decrease compression time, but will result
* in worse compression ratio. Lower values will give better
* compression ratio (more matches found), but will increase time.
*/
#define LZ77_MATCH_MAX_DIST SZ_8K
#define LZ77_HASH_LOG 15
#define LZ77_HASH_SIZE BIT(LZ77_HASH_LOG)
#define LZ77_RSTEP_SIZE sizeof(u32)
#define LZ77_MSTEP_SIZE sizeof(u64)
#define LZ77_SKIP_TRIGGER 4
#define LZ77_PREFETCH(ptr) __builtin_prefetch((ptr), 0, 3)
#define LZ77_FLAG_MAX 32
static __always_inline u8 lz77_read8(const u8 *ptr)
{
return get_unaligned(ptr);
}
static __always_inline u32 lz77_read32(const u32 *ptr)
{
return get_unaligned(ptr);
}
static __always_inline u64 lz77_read64(const u64 *ptr)
{
return get_unaligned(ptr);
}
static __always_inline void lz77_write8(u8 *ptr, u8 v)
{
put_unaligned(v, ptr);
}
static __always_inline void lz77_write16(u16 *ptr, u16 v)
{
put_unaligned_le16(v, ptr);
}
static __always_inline void lz77_write32(u32 *ptr, u32 v)
{
put_unaligned_le32(v, ptr);
}
static __always_inline u32 lz77_match_len(const void *match, const void *cur, const void *end)
{
const void *start = cur;
/* Safe for a do/while because otherwise we wouldn't reach here from the main loop. */
do {
const u64 diff = lz77_read64(cur) ^ lz77_read64(match);
if (!diff) {
cur += LZ77_MSTEP_SIZE;
match += LZ77_MSTEP_SIZE;
continue;
}
/* This computes the number of common bytes in @diff. */
cur += count_trailing_zeros(diff) >> 3;
return (cur - start);
} while (likely(cur + LZ77_MSTEP_SIZE <= end));
/* Fallback to byte-by-byte comparison for last <8 bytes. */
while (cur < end && lz77_read8(cur) == lz77_read8(match)) {
cur++;
match++;
}
return (cur - start);
}
/**
* lz77_encode_match() - Match encoding.
* @dst: compressed buffer
* @nib: pointer to an address in @dst
* @dist: match distance
* @len: match length
*
* Assumes all args were previously checked.
*
* Return: @dst advanced to new position
*
* Ref: MS-XCA 2.3.4 "Plain LZ77 Compression Algorithm Details" - "Processing"
*/
static __always_inline void *lz77_encode_match(void *dst, void **nib, u16 dist, u32 len)
{
len -= 3;
dist--;
dist <<= 3;
if (len < 7) {
lz77_write16(dst, dist + len);
return dst + sizeof(u16);
}
dist |= 7;
lz77_write16(dst, dist);
dst += sizeof(u16);
len -= 7;
if (!*nib) {
lz77_write8(dst, umin(len, 15));
*nib = dst;
dst++;
} else {
u8 *b = *nib;
lz77_write8(b, *b | umin(len, 15) << 4);
*nib = NULL;
}
if (len < 15)
return dst;
len -= 15;
if (len < 255) {
lz77_write8(dst, len);
return dst + 1;
}
lz77_write8(dst, 0xff);
dst++;
len += 7 + 15;
if (len <= 0xffff) {
lz77_write16(dst, len);
return dst + sizeof(u16);
}
lz77_write16(dst, 0);
dst += sizeof(u16);
lz77_write32(dst, len);
return dst + sizeof(u32);
}
/**
* lz77_encode_literals() - Literals encoding.
* @start: where to start copying literals (uncompressed buffer)
* @end: when to stop copying (uncompressed buffer)
* @dst: compressed buffer
* @f: pointer to current flag value
* @fc: pointer to current flag count
* @fp: pointer to current flag address
*
* Batch copy literals from @start to @dst, updating flag values accordingly.
* Assumes all args were previously checked.
*
* Return: @dst advanced to new position
*
* MS-XCA 2.3.4 "Plain LZ77 Compression Algorithm Details" - "Processing"
*/
static __always_inline void *lz77_encode_literals(const void *start, const void *end, void *dst,
long *f, u32 *fc, void **fp)
{
if (start >= end)
return dst;
do {
const u32 len = umin(end - start, LZ77_FLAG_MAX - *fc);
memcpy(dst, start, len);
dst += len;
start += len;
*f <<= len;
*fc += len;
if (*fc == LZ77_FLAG_MAX) {
lz77_write32(*fp, *f);
*fc = 0;
*fp = dst;
dst += sizeof(u32);
}
} while (start < end);
return dst;
}
static __always_inline u32 lz77_hash(const u32 v)
{
return ((v ^ 0x9E3779B9) * 0x85EBCA6B) >> (32 - LZ77_HASH_LOG);
}
noinline int smb_lz77_compress(const void *src, const u32 slen,
void *dst, u32 *dlen)
{
const void *srcp, *rlim, *end, *anchor;
u32 *htable, hash, flag_count = 0;
void *dstp, *nib, *flag_pos;
long flag = 0;
/* This is probably a bug, so throw a warning. */
if (WARN_ON_ONCE(*dlen < smb_lz77_compressed_alloc_size(slen)))
return -EINVAL;
srcp = src;
anchor = src;
end = srcp + slen; /* absolute end */
rlim = end - LZ77_MSTEP_SIZE; /* read limit (for lz77_match_len()) */
dstp = dst;
flag_pos = dstp;
dstp += sizeof(u32);
nib = NULL;
htable = kvcalloc(LZ77_HASH_SIZE, sizeof(*htable), GFP_KERNEL);
if (!htable)
return -ENOMEM;
LZ77_PREFETCH(srcp + LZ77_RSTEP_SIZE);
/*
* Adjust @srcp so we don't get a false positive match on first iteration.
* Then prepare hash for first loop iteration (don't advance @srcp again).
*/
hash = lz77_hash(lz77_read32(srcp++));
htable[hash] = 0;
hash = lz77_hash(lz77_read32(srcp));
/*
* Main loop.
*
* @dlen is >= smb_lz77_compressed_alloc_size(), so run without
* bound-checking @dstp.
*
* This code was crafted in a way to best utilise fetch-decode-execute CPU flow.
* Any attempt to optimize it, or even organize it, can lead to huge performance loss.
*/
do {
const void *match, *next = srcp;
u32 len, step = 1, skip = 1U << LZ77_SKIP_TRIGGER;
/* Match finding (hot path -- don't change the read/check/write order). */
do {
const u32 cur_hash = hash;
srcp = next;
next += step;
/*
* Adaptive skipping.
*
* Increment @step every (1 << LZ77_SKIP_TRIGGER, 16 in our case) bytes
* without a match.
* Reset to 1 when a match is found.
*/
step = (skip++ >> LZ77_SKIP_TRIGGER);
if (unlikely(next > rlim))
goto out;
hash = lz77_hash(lz77_read32(next));
match = src + htable[cur_hash];
htable[cur_hash] = srcp - src;
} while (likely(match + LZ77_MATCH_MAX_DIST < srcp) ||
lz77_read32(match) != lz77_read32(srcp));
/*
* Match found. Warm/cold path; begin parsing @srcp and writing to @dstp:
* - flush literals
* - compute match length (*)
* - encode match
*
* (*) Current minimum match length is defined by the memory read size above, so
* here we already know that we have 4 matching bytes, but it's just faster to
* redundantly compute it again in lz77_match_len() than to adjust pointers/len.
*/
dstp = lz77_encode_literals(anchor, srcp, dstp, &flag, &flag_count, &flag_pos);
len = lz77_match_len(match, srcp, end);
dstp = lz77_encode_match(dstp, &nib, srcp - match, len);
srcp += len;
anchor = srcp;
LZ77_PREFETCH(srcp);
flag = (flag << 1) | 1;
flag_count++;
if (flag_count == LZ77_FLAG_MAX) {
lz77_write32(flag_pos, flag);
flag_count = 0;
flag_pos = dstp;
dstp += sizeof(u32);
}
if (unlikely(srcp > rlim))
break;
/* Prepare for next loop. */
hash = lz77_hash(lz77_read32(srcp));
} while (srcp < end);
out:
dstp = lz77_encode_literals(anchor, end, dstp, &flag, &flag_count, &flag_pos);
flag_count = LZ77_FLAG_MAX - flag_count;
flag <<= flag_count;
flag |= (1UL << flag_count) - 1;
lz77_write32(flag_pos, flag);
*dlen = dstp - dst;
kvfree(htable);
if (*dlen < slen)
return 0;
return -EMSGSIZE;
}
EXPORT_SYMBOL_GPL(smb_lz77_compress);
static int lz77_decode_match_len(const u8 **src, const u8 *end, u16 token,
u8 *nibble, bool *have_nibble, u32 *len)
{
u8 extra;
*len = (token & 0x7) + 3;
if ((token & 0x7) != 0x7)
return 0;
if (!*have_nibble) {
if (*src >= end)
return -EINVAL;
*nibble = *(*src)++;
extra = *nibble & 0xf;
*have_nibble = true;
} else {
extra = *nibble >> 4;
*have_nibble = false;
}
*len += extra;
if (extra == 0xf) {
u8 b;
if (*src >= end)
return -EINVAL;
b = *(*src)++;
if (b != 0xff) {
*len += b;
} else {
u16 w;
if (end - *src < 2)
return -EINVAL;
w = get_unaligned_le16(*src);
*src += 2;
if (w) {
*len = w + 3;
} else {
u32 long_len;
if (end - *src < 4)
return -EINVAL;
long_len = get_unaligned_le32(*src);
*src += 4;
if (check_add_overflow(long_len, 3, len))
return -EINVAL;
}
}
}
return 0;
}
int smb_lz77_decompress(const void *src, const u32 slen, void *dst,
const u32 dlen)
{
const u8 *sp = src, *send = sp + slen;
u8 *dp = dst, *dend = dp + dlen;
u32 flags = 0;
int flag_count = 0;
u8 nibble = 0;
bool have_nibble = false;
while (dp < dend) {
u32 len, dist;
u16 token;
if (!flag_count) {
if (send - sp < 4)
return -EINVAL;
flags = get_unaligned_le32(sp);
sp += 4;
flag_count = 32;
}
if (!(flags & 0x80000000)) {
if (sp >= send)
return -EINVAL;
*dp++ = *sp++;
flags <<= 1;
flag_count--;
continue;
}
flags <<= 1;
flag_count--;
if (send - sp < 2)
return -EINVAL;
token = get_unaligned_le16(sp);
sp += 2;
dist = (token >> 3) + 1;
if (dist > dp - (u8 *)dst)
return -EINVAL;
if (lz77_decode_match_len(&sp, send, token, &nibble,
&have_nibble, &len))
return -EINVAL;
if (len > dend - dp)
return -EINVAL;
while (len--) {
*dp = *(dp - dist);
dp++;
}
}
return 0;
}
EXPORT_SYMBOL_GPL(smb_lz77_decompress);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("SMB plain LZ77 compression");
+46
View File
@@ -0,0 +1,46 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (C) 2024-2026, SUSE LLC
*
* Authors: Enzo Matsumiya <ematsumiya@suse.de>
*
* Implementation of the LZ77 "plain" compression algorithm, as per MS-XCA spec.
*/
#ifndef _SMB_COMPRESS_LZ77_H
#define _SMB_COMPRESS_LZ77_H
#include <linux/kernel.h>
/**
* smb_lz77_compressed_alloc_size() - Compute compressed buffer size.
* @size: uncompressed (src) size
*
* Compute allocation size for the compressed buffer based on uncompressed size.
* Accounts for metadata and overprovision for the worst case scenario.
*
* LZ77 metadata is a 4-byte flag that is written:
* - on dst begin (pos 0)
* - every 32 literals or matches
* - on end-of-stream (possibly, if last write was another flag)
*
* Worst case scenario is an all-literal compression, which means:
* metadata bytes = 4 + ((@size / 32) * 4) + 4, or, simplified, (@size >> 3) + 8
*
* The worst case scenario rarely happens, but such overprovisioning also
* allows smb_lz77_compress() main loop to run without ever bound checking dst,
* which is a huge perf improvement, while also being safe when compression goes
* bad.
*
* Return: required (*) allocation size for compressed buffer.
*
* (*) checked once in the beginning of smb_lz77_compress()
*/
static __always_inline u32 smb_lz77_compressed_alloc_size(const u32 size)
{
return size + (size >> 3) + 8;
}
int smb_lz77_compress(const void *src, const u32 slen, void *dst, u32 *dlen);
int smb_lz77_decompress(const void *src, const u32 slen, void *dst,
const u32 dlen);
#endif /* _SMB_COMPRESS_LZ77_H */
+589
View File
@@ -0,0 +1,589 @@
/* SPDX-License-Identifier: LGPL-2.1 */
/*
*
* Copyright (c) International Business Machines Corp., 2009, 2013
* Etersoft, 2012
* 2018 Samsung Electronics Co., Ltd.
* Author(s): Steve French (sfrench@us.ibm.com)
* Pavel Shilovsky (pshilovsky@samba.org) 2012
* Namjae Jeon (linkinjeon@kernel.org)
*
*/
#ifndef _COMMON_SMB_FSCC_H
#define _COMMON_SMB_FSCC_H
/* Reparse structures - see MS-FSCC 2.1.2 */
/* struct fsctl_reparse_info_req is empty, only response structs (see below) */
struct reparse_data_buffer {
__le32 ReparseTag;
__le16 ReparseDataLength;
__u16 Reserved;
__u8 DataBuffer[]; /* Variable Length */
} __packed;
struct reparse_guid_data_buffer {
__le32 ReparseTag;
__le16 ReparseDataLength;
__u16 Reserved;
__u8 ReparseGuid[16];
__u8 DataBuffer[]; /* Variable Length */
} __packed;
struct reparse_mount_point_data_buffer {
__le32 ReparseTag;
__le16 ReparseDataLength;
__u16 Reserved;
__le16 SubstituteNameOffset;
__le16 SubstituteNameLength;
__le16 PrintNameOffset;
__le16 PrintNameLength;
__u8 PathBuffer[]; /* Variable Length */
} __packed;
#define SYMLINK_FLAG_RELATIVE 0x00000001
struct reparse_symlink_data_buffer {
__le32 ReparseTag;
__le16 ReparseDataLength;
__u16 Reserved;
__le16 SubstituteNameOffset;
__le16 SubstituteNameLength;
__le16 PrintNameOffset;
__le16 PrintNameLength;
__le32 Flags;
__u8 PathBuffer[]; /* Variable Length */
} __packed;
/* For IO_REPARSE_TAG_NFS - see MS-FSCC 2.1.2.6 */
#define NFS_SPECFILE_LNK 0x00000000014B4E4C
#define NFS_SPECFILE_CHR 0x0000000000524843
#define NFS_SPECFILE_BLK 0x00000000004B4C42
#define NFS_SPECFILE_FIFO 0x000000004F464946
#define NFS_SPECFILE_SOCK 0x000000004B434F53
struct reparse_nfs_data_buffer {
__le32 ReparseTag;
__le16 ReparseDataLength;
__u16 Reserved;
__le64 InodeType; /* NFS_SPECFILE_* */
__u8 DataBuffer[];
} __packed;
/* For IO_REPARSE_TAG_LX_SYMLINK - see MS-FSCC 2.1.2.7 */
struct reparse_wsl_symlink_data_buffer {
__le32 ReparseTag;
__le16 ReparseDataLength;
__u16 Reserved;
__le32 Version; /* Always 2 */
__u8 Target[]; /* Variable Length UTF-8 string without nul-term */
} __packed;
/* See MS-FSCC 2.3.7 */
struct duplicate_extents_to_file {
__u64 PersistentFileHandle; /* source file handle, opaque endianness */
__u64 VolatileFileHandle;
__le64 SourceFileOffset;
__le64 TargetFileOffset;
__le64 ByteCount; /* Bytes to be copied */
} __packed;
/* See MS-FSCC 2.3.9 */
#define DUPLICATE_EXTENTS_DATA_EX_SOURCE_ATOMIC 0x00000001
struct duplicate_extents_to_file_ex {
__le64 StructureSize; /* MUST be set to 0x30 */
__u64 PersistentFileHandle; /* source file handle, opaque endianness */
__u64 VolatileFileHandle;
__le64 SourceFileOffset;
__le64 TargetFileOffset;
__le64 ByteCount; /* Bytes to be copied */
__le32 Flags;
__le32 Reserved;
} __packed;
/*
* compression state flags
* See MS-FSCC 2.3.18
* MS-FSCC 2.3.67
* MS-FSCC 2.4.9
*/
#define COMPRESSION_FORMAT_NONE 0x0000
#define COMPRESSION_FORMAT_DEFAULT 0x0001
#define COMPRESSION_FORMAT_LZNT1 0x0002
/*
* See MS-FSCC 2.3.18
* MS-FSCC 2.3.67
*/
struct compress_ioctl {
__le16 CompressionState;
} __packed;
/* See MS-FSCC 2.3.20 */
struct fsctl_get_integrity_information_rsp {
__le16 ChecksumAlgorithm;
__le16 Reserved;
__le32 Flags;
__le32 ChecksumChunkSizeInBytes;
__le32 ClusterSizeInBytes;
} __packed;
/* See MS-FSCC 2.3.52 */
struct file_allocated_range_buffer {
__le64 file_offset;
__le64 length;
} __packed;
/* See MS-FSCC 2.3.55 */
struct fsctl_query_file_regions_req {
__le64 FileOffset;
__le64 Length;
__le32 DesiredUsage;
__le32 Reserved;
} __packed;
/* DesiredUsage flags see MS-FSCC 2.3.56.1 */
#define FILE_USAGE_INVALID_RANGE 0x00000000
#define FILE_USAGE_VALID_CACHED_DATA 0x00000001
#define FILE_USAGE_NONCACHED_DATA 0x00000002
struct file_region_info {
__le64 FileOffset;
__le64 Length;
__le32 DesiredUsage;
__le32 Reserved;
} __packed;
/* See MS-FSCC 2.3.56 */
struct fsctl_query_file_region_rsp {
__le32 Flags;
__le32 TotalRegionEntryCount;
__le32 RegionEntryCount;
__u32 Reserved;
struct file_region_info Regions[];
} __packed;
/* See MS-FSCC 2.3.58 */
struct fsctl_query_on_disk_vol_info_rsp {
__le64 DirectoryCount;
__le64 FileCount;
__le16 FsFormatMajVersion;
__le16 FsFormatMinVersion;
__u8 FsFormatName[24];
__le64 FormatTime;
__le64 LastUpdateTime;
__u8 CopyrightInfo[68];
__u8 AbstractInfo[68];
__u8 FormatImplInfo[68];
__u8 LastModifyImplInfo[68];
} __packed;
/* See MS-FSCC 2.3.73 */
struct fsctl_set_integrity_information_req {
__le16 ChecksumAlgorithm;
__le16 Reserved;
__le32 Flags;
} __packed;
/* See MS-FSCC 2.3.75 */
struct fsctl_set_integrity_info_ex_req {
__u8 EnableIntegrity;
__u8 KeepState;
__u16 Reserved;
__le32 Flags;
__u8 Version;
__u8 Reserved2[7];
} __packed;
/*
* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA
* See MS-FSCC 2.3.85
*/
struct file_zero_data_information {
__le64 FileOffset;
__le64 BeyondFinalZero;
} __packed;
/*
* This level 18, although with struct with same name is different from cifs
* level 0x107. Level 0x107 has an extra u64 between AccessFlags and
* CurrentByteOffset.
* See MS-FSCC 2.4.2
*/
struct smb2_file_all_info { /* data block encoding of response to level 18 */
__le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
__le64 LastAccessTime;
__le64 LastWriteTime;
__le64 ChangeTime;
__le32 Attributes;
__u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
__le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
__le64 EndOfFile; /* size ie offset to first free byte in file */
__le32 NumberOfLinks; /* hard links */
__u8 DeletePending;
__u8 Directory;
__u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
__le64 IndexNumber;
__le32 EASize;
__le32 AccessFlags;
__le64 CurrentByteOffset;
__le32 Mode;
__le32 AlignmentRequirement;
__le32 FileNameLength;
union {
char __pad; /* Legacy structure padding */
DECLARE_FLEX_ARRAY(char, FileName);
};
} __packed; /* level 18 Query */
/* See MS-FSCC 2.4.7 */
typedef struct file_basic_info { /* data block encoding of response to level 18 */
__le64 CreationTime;
__le64 LastAccessTime;
__le64 LastWriteTime;
__le64 ChangeTime;
__le32 Attributes;
__u32 Pad;
} __packed FILE_BASIC_INFO; /* size info, level 0x101 */
/* See MS-FSCC 2.4.8 */
typedef struct {
__le32 NextEntryOffset;
__u32 FileIndex;
__le64 CreationTime;
__le64 LastAccessTime;
__le64 LastWriteTime;
__le64 ChangeTime;
__le64 EndOfFile;
__le64 AllocationSize;
__le32 ExtFileAttributes;
__le32 FileNameLength;
__le32 EaSize; /* length of the xattrs */
__u8 ShortNameLength;
__u8 Reserved;
__u8 ShortName[24];
char FileName[];
} __packed FILE_BOTH_DIRECTORY_INFO; /* level 0x104 FFrsp data */
/* See MS-FSCC 2.4.10 */
typedef struct {
__le32 NextEntryOffset;
__u32 FileIndex;
__le64 CreationTime;
__le64 LastAccessTime;
__le64 LastWriteTime;
__le64 ChangeTime;
__le64 EndOfFile;
__le64 AllocationSize;
__le32 ExtFileAttributes;
__le32 FileNameLength;
char FileName[];
} __packed FILE_DIRECTORY_INFO; /* level 0x101 FF resp data */
/* See MS-FSCC 2.4.14 */
struct smb2_file_eof_info { /* encoding of request for level 10 */
__le64 EndOfFile; /* new end of file value */
} __packed; /* level 20 Set */
/* See MS-FSCC 2.4.4 */
struct smb2_file_alloc_info { /* encoding of request for level 19 */
__le64 AllocationSize;
} __packed;
/* See MS-FSCC 2.4.15 */
typedef struct {
__le32 NextEntryOffset;
__u32 FileIndex;
__le64 CreationTime;
__le64 LastAccessTime;
__le64 LastWriteTime;
__le64 ChangeTime;
__le64 EndOfFile;
__le64 AllocationSize;
__le32 ExtFileAttributes;
__le32 FileNameLength;
__le32 EaSize; /* length of the xattrs */
char FileName[];
} __packed FILE_FULL_DIRECTORY_INFO; /* level 0x102 rsp data */
/* See MS-FSCC 2.4.24 */
typedef struct {
__le32 NextEntryOffset;
__u32 FileIndex;
__le64 CreationTime;
__le64 LastAccessTime;
__le64 LastWriteTime;
__le64 ChangeTime;
__le64 EndOfFile;
__le64 AllocationSize;
__le32 ExtFileAttributes;
__le32 FileNameLength;
__le32 EaSize; /* EA size */
__le32 Reserved;
__le64 UniqueId; /* inode num - le since Samba puts ino in low 32 bit*/
char FileName[];
} __packed FILE_ID_FULL_DIR_INFO; /* level 0x105 FF rsp data */
/* See MS-FSCC 2.4.27 */
struct smb2_file_internal_info {
__le64 IndexNumber;
} __packed; /* level 6 Query */
/* See MS-FSCC 2.4.28.2 */
struct smb2_file_link_info { /* encoding of request for level 11 */
/* New members MUST be added within the struct_group() macro below. */
__struct_group(smb2_file_link_info_hdr, __hdr, __packed,
__u8 ReplaceIfExists; /* 1 = replace existing link with new */
/* 0 = fail if link already exists */
__u8 Reserved[7];
__u64 RootDirectory; /* MBZ for network operations (why says spec?) */
__le32 FileNameLength;
);
char FileName[]; /* Name to be assigned to new link */
} __packed; /* level 11 Set */
static_assert(offsetof(struct smb2_file_link_info, FileName) == sizeof(struct smb2_file_link_info_hdr),
"struct member likely outside of __struct_group()");
/* See MS-FSCC 2.4.34 */
struct smb2_file_network_open_info {
struct_group_attr(network_open_info, __packed,
__le64 CreationTime;
__le64 LastAccessTime;
__le64 LastWriteTime;
__le64 ChangeTime;
__le64 AllocationSize;
__le64 EndOfFile;
__le32 Attributes;
);
__le32 Reserved;
} __packed; /* level 34 Query also similar returned in close rsp and open rsp */
/* See MS-FSCC 2.4.42.2 */
struct smb2_file_rename_info { /* encoding of request for level 10 */
/* New members MUST be added within the struct_group() macro below. */
__struct_group(smb2_file_rename_info_hdr, __hdr, __packed,
__u8 ReplaceIfExists; /* 1 = replace existing target with new */
/* 0 = fail if target already exists */
__u8 Reserved[7];
__u64 RootDirectory; /* MBZ for network operations (why says spec?) */
__le32 FileNameLength;
);
char FileName[]; /* New name to be assigned */
/* padding - overall struct size must be >= 24 so filename + pad >= 6 */
} __packed; /* level 10 Set */
static_assert(offsetof(struct smb2_file_rename_info, FileName) == sizeof(struct smb2_file_rename_info_hdr),
"struct member likely outside of __struct_group()");
/* File System Information Classes */
/* See MS-FSCC 2.5 */
#define FS_VOLUME_INFORMATION 1 /* Query */
#define FS_LABEL_INFORMATION 2 /* Set */
#define FS_SIZE_INFORMATION 3 /* Query */
#define FS_DEVICE_INFORMATION 4 /* Query */
#define FS_ATTRIBUTE_INFORMATION 5 /* Query */
#define FS_CONTROL_INFORMATION 6 /* Query, Set */
#define FS_FULL_SIZE_INFORMATION 7 /* Query */
#define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
#define FS_DRIVER_PATH_INFORMATION 9 /* Query */
#define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
/* See POSIX Extensions to MS-FSCC 2.3.1.1 */
#define FS_POSIX_INFORMATION 100 /* SMB3.1.1 POSIX. Query */
/* See MS-FSCC 2.5.1 */
#define MAX_FS_NAME_LEN 52
typedef struct {
__le32 Attributes;
__le32 MaxPathNameComponentLength;
__le32 FileSystemNameLen;
__le16 FileSystemName[]; /* do not have to save this - get subset? */
} __packed FILE_SYSTEM_ATTRIBUTE_INFO;
/* List of FileSystemAttributes - see MS-FSCC 2.5.1 */
#define FILE_SUPPORTS_SPARSE_VDL 0x10000000 /* faster nonsparse extend */
#define FILE_SUPPORTS_BLOCK_REFCOUNTING 0x08000000 /* allow ioctl dup extents */
#define FILE_SUPPORT_INTEGRITY_STREAMS 0x04000000
#define FILE_SUPPORTS_USN_JOURNAL 0x02000000
#define FILE_SUPPORTS_OPEN_BY_FILE_ID 0x01000000
#define FILE_SUPPORTS_EXTENDED_ATTRIBUTES 0x00800000
#define FILE_SUPPORTS_HARD_LINKS 0x00400000
#define FILE_SUPPORTS_TRANSACTIONS 0x00200000
#define FILE_SEQUENTIAL_WRITE_ONCE 0x00100000
#define FILE_READ_ONLY_VOLUME 0x00080000
#define FILE_NAMED_STREAMS 0x00040000
#define FILE_SUPPORTS_ENCRYPTION 0x00020000
#define FILE_SUPPORTS_OBJECT_IDS 0x00010000
#define FILE_VOLUME_IS_COMPRESSED 0x00008000
#define FILE_SUPPORTS_POSIX_UNLINK_RENAME 0x00000400
#define FILE_RETURNS_CLEANUP_RESULT_INFO 0x00000200
#define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100
#define FILE_SUPPORTS_REPARSE_POINTS 0x00000080
#define FILE_SUPPORTS_SPARSE_FILES 0x00000040
#define FILE_VOLUME_QUOTAS 0x00000020
#define FILE_FILE_COMPRESSION 0x00000010
#define FILE_PERSISTENT_ACLS 0x00000008
#define FILE_UNICODE_ON_DISK 0x00000004
#define FILE_CASE_PRESERVED_NAMES 0x00000002
#define FILE_CASE_SENSITIVE_SEARCH 0x00000001
/*
* File System Control Information
* See MS-FSCC 2.5.2
*/
struct smb2_fs_control_info {
__le64 FreeSpaceStartFiltering;
__le64 FreeSpaceThreshold;
__le64 FreeSpaceStopFiltering;
__le64 DefaultQuotaThreshold;
__le64 DefaultQuotaLimit;
__le32 FileSystemControlFlags;
__le32 Padding;
} __packed;
/* See MS-FSCC 2.5.4 */
struct smb2_fs_full_size_info {
__le64 TotalAllocationUnits;
__le64 CallerAvailableAllocationUnits;
__le64 ActualAvailableAllocationUnits;
__le32 SectorsPerAllocationUnit;
__le32 BytesPerSector;
} __packed;
/* See MS-FSCC 2.5.7 */
#define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
#define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
#define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
#define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
/* sector size info struct */
struct smb3_fs_ss_info {
__le32 LogicalBytesPerSector;
__le32 PhysicalBytesPerSectorForAtomicity;
__le32 PhysicalBytesPerSectorForPerf;
__le32 FSEffPhysicalBytesPerSectorForAtomicity;
__le32 Flags;
__le32 ByteOffsetForSectorAlignment;
__le32 ByteOffsetForPartitionAlignment;
} __packed;
/* See MS-FSCC 2.5.8 */
typedef struct {
__le64 TotalAllocationUnits;
__le64 AvailableAllocationUnits;
__le32 SectorsPerAllocationUnit;
__le32 BytesPerSector;
} __packed FILE_SYSTEM_SIZE_INFO; /* size info, level 0x103 */
/* volume info struct - see MS-FSCC 2.5.9 */
#define MAX_VOL_LABEL_LEN 32
struct filesystem_vol_info {
__le64 VolumeCreationTime;
__le32 VolumeSerialNumber;
__le32 VolumeLabelLength; /* includes trailing null */
__u8 SupportsObjects; /* True if eg like NTFS, supports objects */
__u8 Reserved;
__u8 VolumeLabel[]; /* variable len */
} __packed;
/* See MS-FSCC 2.5.10 */
typedef struct {
__le32 DeviceType;
__le32 DeviceCharacteristics;
} __packed FILE_SYSTEM_DEVICE_INFO; /* device info level 0x104 */
/*
* File Attributes
* See MS-FSCC 2.6
*/
#define FILE_ATTRIBUTE_READONLY 0x00000001
#define FILE_ATTRIBUTE_HIDDEN 0x00000002
#define FILE_ATTRIBUTE_SYSTEM 0x00000004
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
#define FILE_ATTRIBUTE_NORMAL 0x00000080
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
#define FILE_ATTRIBUTE_OFFLINE 0x00001000
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
#define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
#define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
#define FILE_ATTRIBUTE_MASK (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | \
FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY | \
FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_NORMAL | \
FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_SPARSE_FILE | \
FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_COMPRESSED | \
FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED | \
FILE_ATTRIBUTE_ENCRYPTED | FILE_ATTRIBUTE_INTEGRITY_STREAM | \
FILE_ATTRIBUTE_NO_SCRUB_DATA)
#define FILE_ATTRIBUTE_READONLY_LE cpu_to_le32(FILE_ATTRIBUTE_READONLY)
#define FILE_ATTRIBUTE_HIDDEN_LE cpu_to_le32(FILE_ATTRIBUTE_HIDDEN)
#define FILE_ATTRIBUTE_SYSTEM_LE cpu_to_le32(FILE_ATTRIBUTE_SYSTEM)
#define FILE_ATTRIBUTE_DIRECTORY_LE cpu_to_le32(FILE_ATTRIBUTE_DIRECTORY)
#define FILE_ATTRIBUTE_ARCHIVE_LE cpu_to_le32(FILE_ATTRIBUTE_ARCHIVE)
#define FILE_ATTRIBUTE_NORMAL_LE cpu_to_le32(FILE_ATTRIBUTE_NORMAL)
#define FILE_ATTRIBUTE_TEMPORARY_LE cpu_to_le32(FILE_ATTRIBUTE_TEMPORARY)
#define FILE_ATTRIBUTE_SPARSE_FILE_LE cpu_to_le32(FILE_ATTRIBUTE_SPARSE_FILE)
#define FILE_ATTRIBUTE_REPARSE_POINT_LE cpu_to_le32(FILE_ATTRIBUTE_REPARSE_POINT)
#define FILE_ATTRIBUTE_COMPRESSED_LE cpu_to_le32(FILE_ATTRIBUTE_COMPRESSED)
#define FILE_ATTRIBUTE_OFFLINE_LE cpu_to_le32(FILE_ATTRIBUTE_OFFLINE)
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED_LE cpu_to_le32(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)
#define FILE_ATTRIBUTE_ENCRYPTED_LE cpu_to_le32(FILE_ATTRIBUTE_ENCRYPTED)
#define FILE_ATTRIBUTE_INTEGRITY_STREAM_LE cpu_to_le32(FILE_ATTRIBUTE_INTEGRITY_STREAM)
#define FILE_ATTRIBUTE_NO_SCRUB_DATA_LE cpu_to_le32(FILE_ATTRIBUTE_NO_SCRUB_DATA)
#define FILE_ATTRIBUTE_MASK_LE cpu_to_le32(FILE_ATTRIBUTE_MASK)
/*
* SMB2 Notify Action Flags
* See MS-FSCC 2.7.1
*/
#define FILE_ACTION_ADDED 0x00000001
#define FILE_ACTION_REMOVED 0x00000002
#define FILE_ACTION_MODIFIED 0x00000003
#define FILE_ACTION_RENAMED_OLD_NAME 0x00000004
#define FILE_ACTION_RENAMED_NEW_NAME 0x00000005
#define FILE_ACTION_ADDED_STREAM 0x00000006
#define FILE_ACTION_REMOVED_STREAM 0x00000007
#define FILE_ACTION_MODIFIED_STREAM 0x00000008
#define FILE_ACTION_REMOVED_BY_DELETE 0x00000009
#define FILE_ACTION_ID_NOT_TUNNELLED 0x0000000A
#define FILE_ACTION_TUNNELLED_ID_COLLISION 0x0000000B
/*
* Response contains array of the following structures
* See MS-FSCC 2.7.1
*/
struct file_notify_information {
__le32 NextEntryOffset;
__le32 Action;
__le32 FileNameLength;
__u8 FileName[];
} __packed;
/*
* See POSIX Extensions to MS-FSCC 2.3.2.1
* Link: https://gitlab.com/samba-team/smb3-posix-spec/-/blob/master/fscc_posix_extensions.md
*/
typedef struct {
/* For undefined recommended transfer size return -1 in that field */
__le32 OptimalTransferSize; /* bsize on some os, iosize on other os */
__le32 BlockSize;
/* The next three fields are in terms of the block size.
* (above). If block size is unknown, 4096 would be a
* reasonable block size for a server to report.
* Note that returning the blocks/blocksavail removes need
* to make a second call (to QFSInfo level 0x103 to get this info.
* UserBlockAvail is typically less than or equal to BlocksAvail,
* if no distinction is made return the same value in each
*/
__le64 TotalBlocks;
__le64 BlocksAvail; /* bfree */
__le64 UserBlocksAvail; /* bavail */
/* For undefined Node fields or FSID return -1 */
__le64 TotalFileNodes;
__le64 FreeFileNodes;
__le64 FileSysIdentifier; /* fsid */
/* NB Namelen comes from FILE_SYSTEM_ATTRIBUTE_INFO call */
/* NB flags can come from FILE_SYSTEM_DEVICE_INFO call */
} __packed FILE_SYSTEM_POSIX_INFO;
#endif /* _COMMON_SMB_FSCC_H */
+27
View File
@@ -0,0 +1,27 @@
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Common values for ARC4 Cipher Algorithm
*/
#ifndef _CIFS_MD4_H
#define _CIFS_MD4_H
#include <linux/types.h>
#define MD4_DIGEST_SIZE 16
#define MD4_HMAC_BLOCK_SIZE 64
#define MD4_BLOCK_WORDS 16
#define MD4_HASH_WORDS 4
struct md4_ctx {
u32 hash[MD4_HASH_WORDS];
u32 block[MD4_BLOCK_WORDS];
u64 byte_count;
};
int cifs_md4_init(struct md4_ctx *mctx);
int cifs_md4_update(struct md4_ctx *mctx, const u8 *data, unsigned int len);
int cifs_md4_final(struct md4_ctx *mctx, u8 *out);
#endif /* _CIFS_MD4_H */
+56
View File
@@ -0,0 +1,56 @@
/* SPDX-License-Identifier: LGPL-2.1 */
/*
*
* Copyright (C) International Business Machines Corp., 2002,2009
* 2018 Samsung Electronics Co., Ltd.
* Author(s): Steve French <sfrench@us.ibm.com>
* Namjae Jeon <linkinjeon@kernel.org>
*
*/
#ifndef _COMMON_SMB1_PDU_H
#define _COMMON_SMB1_PDU_H
#define SMB1_PROTO_NUMBER cpu_to_le32(0x424d53ff)
/*
* See MS-CIFS 2.2.3.1
* MS-SMB 2.2.3.1
*/
struct smb_hdr {
__u8 Protocol[4];
__u8 Command;
union {
struct {
__u8 ErrorClass;
__u8 Reserved;
__le16 Error;
} __packed DosError;
__le32 CifsError;
} __packed Status;
__u8 Flags;
__le16 Flags2; /* note: le */
__le16 PidHigh;
union {
struct {
__le32 SequenceNumber; /* le */
__u32 Reserved; /* zero */
} __packed Sequence;
__u8 SecuritySignature[8]; /* le */
} __packed Signature;
__u8 pad[2];
__u16 Tid;
__le16 Pid;
__u16 Uid;
__le16 Mid;
__u8 WordCount;
} __packed;
/* See MS-CIFS 2.2.4.52.1 */
typedef struct smb_negotiate_req {
struct smb_hdr hdr; /* wct = 0 */
__le16 ByteCount;
unsigned char DialectsArray[];
} __packed SMB_NEGOTIATE_REQ;
#endif /* _COMMON_SMB1_PDU_H */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+122
View File
@@ -0,0 +1,122 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
/*
* Copyright (c) International Business Machines Corp., 2007
* Author(s): Steve French (sfrench@us.ibm.com)
* Modified by Namjae Jeon (linkinjeon@kernel.org)
*/
#ifndef _COMMON_SMBACL_H
#define _COMMON_SMBACL_H
#define NUM_AUTHS (6) /* number of authority fields */
#define SID_MAX_SUB_AUTHORITIES (15) /* max number of sub authority fields */
/* ACE types - see MS-DTYP 2.4.4.1 */
#define ACCESS_ALLOWED_ACE_TYPE 0x00
#define ACCESS_DENIED_ACE_TYPE 0x01
#define SYSTEM_AUDIT_ACE_TYPE 0x02
#define SYSTEM_ALARM_ACE_TYPE 0x03
#define ACCESS_ALLOWED_COMPOUND_ACE_TYPE 0x04
#define ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05
#define ACCESS_DENIED_OBJECT_ACE_TYPE 0x06
#define SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07
#define SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08
#define ACCESS_ALLOWED_CALLBACK_ACE_TYPE 0x09
#define ACCESS_DENIED_CALLBACK_ACE_TYPE 0x0A
#define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE 0x0B
#define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE 0x0C
#define SYSTEM_AUDIT_CALLBACK_ACE_TYPE 0x0D
#define SYSTEM_ALARM_CALLBACK_ACE_TYPE 0x0E /* Reserved */
#define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE 0x0F
#define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE 0x10 /* reserved */
#define SYSTEM_MANDATORY_LABEL_ACE_TYPE 0x11
#define SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE 0x12
#define SYSTEM_SCOPED_POLICY_ID_ACE_TYPE 0x13
/* ACE flags */
#define OBJECT_INHERIT_ACE 0x01
#define CONTAINER_INHERIT_ACE 0x02
#define NO_PROPAGATE_INHERIT_ACE 0x04
#define INHERIT_ONLY_ACE 0x08
#define INHERITED_ACE 0x10
#define SUCCESSFUL_ACCESS_ACE_FLAG 0x40
#define FAILED_ACCESS_ACE_FLAG 0x80
/*
* Maximum size of a string representation of a SID:
*
* The fields are unsigned values in decimal. So:
*
* u8: max 3 bytes in decimal
* u32: max 10 bytes in decimal
*
* "S-" + 3 bytes for version field + 15 for authority field + NULL terminator
*
* For authority field, max is when all 6 values are non-zero and it must be
* represented in hex. So "-0x" + 12 hex digits.
*
* Add 11 bytes for each subauthority field (10 bytes each + 1 for '-')
*/
#define SID_STRING_BASE_SIZE (2 + 3 + 15 + 1)
#define SID_STRING_SUBAUTH_SIZE (11) /* size of a single subauth string */
#define DOMAIN_USER_RID_LE cpu_to_le32(513)
/*
* ACE types - see MS-DTYP 2.4.4.1
*/
enum {
ACCESS_ALLOWED,
ACCESS_DENIED,
};
/*
* Security ID types
*/
enum {
SIDOWNER = 1,
SIDGROUP,
SIDCREATOR_OWNER,
SIDCREATOR_GROUP,
SIDUNIX_USER,
SIDUNIX_GROUP,
SIDNFS_USER,
SIDNFS_GROUP,
SIDNFS_MODE,
};
struct smb_ntsd {
__le16 revision; /* revision level */
__le16 type;
__le32 osidoffset;
__le32 gsidoffset;
__le32 sacloffset;
__le32 dacloffset;
} __packed;
struct smb_sid {
__u8 revision; /* revision level */
__u8 num_subauth;
__u8 authority[NUM_AUTHS];
__le32 sub_auth[SID_MAX_SUB_AUTHORITIES]; /* sub_auth[num_subauth] */
} __packed;
/* size of a struct smb_sid, sans sub_auth array */
#define CIFS_SID_BASE_SIZE (1 + 1 + NUM_AUTHS)
struct smb_acl {
__le16 revision; /* revision level */
__le16 size;
__le16 num_aces;
__le16 reserved;
} __packed;
struct smb_ace {
__u8 type; /* see above and MS-DTYP 2.4.4.1 */
__u8 flags;
__le16 size;
__le32 access_req;
struct smb_sid sid; /* ie UUID of user or group who gets these perms */
} __packed;
#endif /* _COMMON_SMBACL_H */
+174
View File
@@ -0,0 +1,174 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
/*
* SMB, CIFS, SMB2 FSCTL definitions
*
* Copyright (c) International Business Machines Corp., 2002,2013
* Author(s): Steve French (sfrench@us.ibm.com)
*
*/
/* IOCTL information */
/*
* List of ioctl/fsctl function codes that are or could be useful in the
* future to remote clients like cifs or SMB2/SMB3 client. This is probably
* a slightly larger set of fsctls that NTFS local filesystem could handle,
* including the seven below that we do not have struct definitions for.
* Even with protocol definitions for most of these now available, we still
* need to do some experimentation to identify which are practical to do
* remotely. Some of the following, such as the encryption/compression ones
* could be invoked from tools via a specialized hook into the VFS rather
* than via the standard vfs entry points
*
* See MS-SMB2 Section 2.2.31 (last checked September 2021, all of that list are
* below). Additional detail on less common ones can be found in MS-FSCC
* section 2.3.
*/
#ifndef __SMBFSCTL_H
#define __SMBFSCTL_H
/*
* FSCTL values are 32 bits and are constructed as
* <device 16bits> <access 2bits> <function 12bits> <method 2bits>
*/
/* Device */
#define FSCTL_DEVICE_DFS (0x0006 << 16)
#define FSCTL_DEVICE_FILE_SYSTEM (0x0009 << 16)
#define FSCTL_DEVICE_NAMED_PIPE (0x0011 << 16)
#define FSCTL_DEVICE_NETWORK_FILE_SYSTEM (0x0014 << 16)
#define FSCTL_DEVICE_MASK 0xffff0000
/* Access */
#define FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS (0x00 << 14)
#define FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS (0x01 << 14)
#define FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS (0x02 << 14)
#define FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS (0x03 << 14)
#define FSCTL_DEVICE_ACCESS_MASK 0x0000c000
/* Function */
#define FSCTL_DEVICE_FUNCTION_MASK 0x00003ffc
/* Method */
#define FSCTL_DEVICE_METHOD_BUFFERED 0x00
#define FSCTL_DEVICE_METHOD_IN_DIRECT 0x01
#define FSCTL_DEVICE_METHOD_OUT_DIRECT 0x02
#define FSCTL_DEVICE_METHOD_NEITHER 0x03
#define FSCTL_DEVICE_METHOD_MASK 0x00000003
#define FSCTL_DFS_GET_REFERRALS 0x00060194
#define FSCTL_DFS_GET_REFERRALS_EX 0x000601B0
#define FSCTL_REQUEST_OPLOCK_LEVEL_1 0x00090000
#define FSCTL_REQUEST_OPLOCK_LEVEL_2 0x00090004
#define FSCTL_REQUEST_BATCH_OPLOCK 0x00090008
#define FSCTL_LOCK_VOLUME 0x00090018
#define FSCTL_UNLOCK_VOLUME 0x0009001C
#define FSCTL_IS_PATHNAME_VALID 0x0009002C /* BB add struct */
#define FSCTL_GET_COMPRESSION 0x0009003C
#define FSCTL_SET_COMPRESSION 0x0009C040
#define FSCTL_QUERY_FAT_BPB 0x00090058 /* BB add struct */
/* Verify the next FSCTL number, we had it as 0x00090090 before */
#define FSCTL_FILESYSTEM_GET_STATS 0x00090060 /* BB add struct */
#define FSCTL_GET_NTFS_VOLUME_DATA 0x00090064 /* BB add struct */
#define FSCTL_GET_RETRIEVAL_POINTERS 0x00090073 /* BB add struct */
#define FSCTL_IS_VOLUME_DIRTY 0x00090078 /* BB add struct */
#define FSCTL_ALLOW_EXTENDED_DASD_IO 0x00090083 /* BB add struct */
#define FSCTL_REQUEST_FILTER_OPLOCK 0x0009008C
#define FSCTL_FIND_FILES_BY_SID 0x0009008F /* BB add struct */
#define FSCTL_SET_OBJECT_ID 0x00090098 /* BB add struct */
#define FSCTL_GET_OBJECT_ID 0x0009009C /* BB add struct */
#define FSCTL_DELETE_OBJECT_ID 0x000900A0 /* BB add struct */
#define FSCTL_SET_REPARSE_POINT 0x000900A4 /* BB add struct */
#define FSCTL_GET_REPARSE_POINT 0x000900A8 /* BB add struct */
#define FSCTL_DELETE_REPARSE_POINT 0x000900AC /* BB add struct */
#define FSCTL_SET_OBJECT_ID_EXTENDED 0x000900BC /* BB add struct */
#define FSCTL_CREATE_OR_GET_OBJECT_ID 0x000900C0 /* BB add struct */
#define FSCTL_SET_SPARSE 0x000900C4 /* BB add struct */
#define FSCTL_SET_ZERO_DATA 0x000980C8
#define FSCTL_SET_ENCRYPTION 0x000900D7 /* BB add struct */
#define FSCTL_ENCRYPTION_FSCTL_IO 0x000900DB /* BB add struct */
#define FSCTL_WRITE_RAW_ENCRYPTED 0x000900DF /* BB add struct */
#define FSCTL_READ_RAW_ENCRYPTED 0x000900E3 /* BB add struct */
#define FSCTL_READ_FILE_USN_DATA 0x000900EB /* BB add struct */
#define FSCTL_WRITE_USN_CLOSE_RECORD 0x000900EF /* BB add struct */
#define FSCTL_MARK_HANDLE 0x000900FC /* BB add struct */
#define FSCTL_SIS_COPYFILE 0x00090100 /* BB add struct */
#define FSCTL_RECALL_FILE 0x00090117 /* BB add struct */
#define FSCTL_QUERY_SPARING_INFO 0x00090138 /* BB add struct */
#define FSCTL_QUERY_ON_DISK_VOLUME_INFO 0x0009013C
#define FSCTL_SET_ZERO_ON_DEALLOC 0x00090194 /* BB add struct */
#define FSCTL_SET_SHORT_NAME_BEHAVIOR 0x000901B4 /* BB add struct */
#define FSCTL_GET_INTEGRITY_INFORMATION 0x0009027C
#define FSCTL_QUERY_FILE_REGIONS 0x00090284
#define FSCTL_GET_REFS_VOLUME_DATA 0x000902D8 /* See MS-FSCC 2.3.24 */
#define FSCTL_SET_INTEGRITY_INFORMATION_EXT 0x00090380
#define FSCTL_GET_RETRIEVAL_POINTERS_AND_REFCOUNT 0x000903d3
#define FSCTL_GET_RETRIEVAL_POINTER_COUNT 0x0009042b
#define FSCTL_REFS_STREAM_SNAPSHOT_MANAGEMENT 0x00090440
#define FSCTL_QUERY_ALLOCATED_RANGES 0x000940CF
#define FSCTL_OFFLOAD_READ 0x00094264 /* BB add struct */
#define FSCTL_OFFLOAD_WRITE 0x00098268 /* BB add struct */
#define FSCTL_SET_DEFECT_MANAGEMENT 0x00098134 /* BB add struct */
#define FSCTL_FILE_LEVEL_TRIM 0x00098208 /* BB add struct */
#define FSCTL_DUPLICATE_EXTENTS_TO_FILE 0x00098344
#define FSCTL_DUPLICATE_EXTENTS_TO_FILE_EX 0x000983E8
#define FSCTL_SIS_LINK_FILES 0x0009C104
#define FSCTL_SET_INTEGRITY_INFORMATION 0x0009C280
#define FSCTL_PIPE_PEEK 0x0011400C /* BB add struct */
#define FSCTL_PIPE_TRANSCEIVE 0x0011C017 /* BB add struct */
/* strange that the number for this op is not sequential with previous op */
#define FSCTL_PIPE_WAIT 0x00110018 /* BB add struct */
/* Enumerate previous versions of a file */
#define FSCTL_SRV_ENUMERATE_SNAPSHOTS 0x00144064
/* Retrieve an opaque file reference for server-side data movement ie copy */
#define FSCTL_SRV_REQUEST_RESUME_KEY 0x00140078
#define FSCTL_LMR_REQUEST_RESILIENCY 0x001401D4
#define FSCTL_LMR_GET_LINK_TRACK_INF 0x001400E8 /* BB add struct */
#define FSCTL_LMR_SET_LINK_TRACK_INF 0x001400EC /* BB add struct */
#define FSCTL_VALIDATE_NEGOTIATE_INFO 0x00140204
/* Perform server-side data movement */
#define FSCTL_SRV_COPYCHUNK 0x001440F2
#define FSCTL_SRV_COPYCHUNK_WRITE 0x001480F2
#define FSCTL_QUERY_NETWORK_INTERFACE_INFO 0x001401FC /* BB add struct */
#define FSCTL_SRV_READ_HASH 0x001441BB /* BB add struct */
/* See FSCC 2.1.2.5 */
#define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
#define IO_REPARSE_TAG_HSM 0xC0000004
#define IO_REPARSE_TAG_SIS 0x80000007
#define IO_REPARSE_TAG_HSM2 0x80000006
#define IO_REPARSE_TAG_DRIVER_EXTENDER 0x80000005
/* Used by the DFS filter. See MS-DFSC */
#define IO_REPARSE_TAG_DFS 0x8000000A
/* Used by the DFS filter See MS-DFSC */
#define IO_REPARSE_TAG_DFSR 0x80000012
#define IO_REPARSE_TAG_FILTER_MANAGER 0x8000000B
/* Native SMB symlinks since Windows Vista, see MS-FSCC 2.1.2.4 */
#define IO_REPARSE_TAG_SYMLINK 0xA000000C
#define IO_REPARSE_TAG_DEDUP 0x80000013
#define IO_REPARSE_APPXSTREAM 0xC0000014
/* NFS special files used by Windows NFS server since Windows Server 2012, see MS-FSCC 2.1.2.6 */
#define IO_REPARSE_TAG_NFS 0x80000014
/*
* AzureFileSync - see
* https://docs.microsoft.com/en-us/azure/storage/files/storage-sync-cloud-tiering
*/
#define IO_REPARSE_TAG_AZ_FILE_SYNC 0x8000001e
/* Native Win32 AF_UNIX sockets since Windows 10 April 2018 Update, used also by WSL */
#define IO_REPARSE_TAG_AF_UNIX 0x80000023
/* WSL reparse tags */
#define IO_REPARSE_TAG_LX_SYMLINK 0xA000001D
#define IO_REPARSE_TAG_LX_FIFO 0x80000024
#define IO_REPARSE_TAG_LX_CHR 0x80000025
#define IO_REPARSE_TAG_LX_BLK 0x80000026
#define IO_REPARSE_TAG_LX_SYMLINK_LE cpu_to_le32(IO_REPARSE_TAG_LX_SYMLINK)
#define IO_REPARSE_TAG_AF_UNIX_LE cpu_to_le32(IO_REPARSE_TAG_AF_UNIX)
#define IO_REPARSE_TAG_LX_FIFO_LE cpu_to_le32(IO_REPARSE_TAG_LX_FIFO)
#define IO_REPARSE_TAG_LX_CHR_LE cpu_to_le32(IO_REPARSE_TAG_LX_CHR)
#define IO_REPARSE_TAG_LX_BLK_LE cpu_to_le32(IO_REPARSE_TAG_LX_BLK)
/* If Name Surrogate Bit is set, the file or directory represents another named entity in the system. */
#define IS_REPARSE_TAG_NAME_SURROGATE(tag) (!!((tag) & 0x20000000))
/* fsctl flags */
/* If Flags is set to this value, the request is an FSCTL not ioctl request */
#define SMB2_0_IOCTL_IS_FSCTL 0x00000001
#endif /* __SMBFSCTL_H */
+69
View File
@@ -0,0 +1,69 @@
/* SPDX-License-Identifier: LGPL-2.1 */
/*
*
* Copyright (C) International Business Machines Corp., 2002,2008
* 2018 Samsung Electronics Co., Ltd.
* Author(s): Steve French (sfrench@us.ibm.com)
* Jeremy Allison (jra@samba.org)
* Namjae Jeon (linkinjeon@kernel.org)
*
*/
#ifndef _COMMON_SMB_GLOB_H
#define _COMMON_SMB_GLOB_H
struct smb_version_values {
char *version_string;
__u16 protocol_id;
__le16 lock_cmd;
__u32 req_capabilities;
__u32 max_read_size;
__u32 max_write_size;
__u32 max_trans_size;
__u32 max_credits;
__u32 large_lock_type;
__u32 exclusive_lock_type;
__u32 shared_lock_type;
__u32 unlock_lock_type;
size_t header_size;
size_t max_header_size;
size_t read_rsp_size;
unsigned int cap_unix;
unsigned int cap_nt_find;
unsigned int cap_large_files;
unsigned int cap_unicode;
__u16 signing_enabled;
__u16 signing_required;
size_t create_lease_size;
size_t create_durable_size;
size_t create_durable_v2_size;
size_t create_mxac_size;
size_t create_disk_id_size;
size_t create_posix_size;
};
static inline unsigned int get_rfc1002_len(void *buf)
{
return be32_to_cpu(*((__be32 *)buf)) & 0xffffff;
}
static inline void inc_rfc1001_len(void *buf, int count)
{
be32_add_cpu((__be32 *)buf, count);
}
#define SMB1_VERSION_STRING "1.0"
#define SMB20_VERSION_STRING "2.0"
#define SMB21_VERSION_STRING "2.1"
#define SMBDEFAULT_VERSION_STRING "default"
#define SMB3ANY_VERSION_STRING "3"
#define SMB30_VERSION_STRING "3.0"
#define SMB302_VERSION_STRING "3.02"
#define ALT_SMB302_VERSION_STRING "3.0.2"
#define SMB311_VERSION_STRING "3.1.1"
#define ALT_SMB311_VERSION_STRING "3.11"
#define CIFS_DEFAULT_IOSIZE (1024 * 1024)
#define MAX_CIFS_SMALL_BUFFER_SIZE 448 /* big enough for most */
#endif /* _COMMON_SMB_GLOB_H */