Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: RootSys GmbH Research <team@rootsys.at>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: Michail Andreas Michalopoulos <mike.michalo@gmail.com>,
	Ian Bridges <icb@fastmail.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Tom Talpey <tom@talpey.com>,
	ChenXiaoSong <chenxiaosong@chenxiaosong.com>,
	linux-cifs@vger.kernel.org,
	RootSys GmbH Research <research@rootsys.at>
Subject: [PATCH v3 0/5] ksmbd: enforce mandatory signing and encryption on requests
Date: Fri,  4 Dec 2026 07:53:22 +0100	[thread overview]
Message-ID: <cover.1796365947.git.research@rootsys.at> (raw)

From: RootSys GmbH Research <research@rootsys.at>

ksmbd does not enforce "server signing = mandatory" or "smb3 encryption =
mandatory" on requests once a client has offered a cipher in NEGOTIATE,
which the Linux and current Windows clients always do. sess->sign is
cleared for such sessions, and the gate added by 2bebf2470af1 ("ksmbd:
enforce signing required by the session") only looks at sess->sign, so
an unsigned plaintext request is executed on a session that requires
signing, and a plaintext request on a session that was told
SMB2_SESSION_FLAG_ENCRYPT_DATA. A client that cannot encrypt gets a
plaintext session even with mandatory encryption, and so does a
SESSION_SETUP that sets SMB2_SESSION_REQ_FLAG_BINDING without a
SessionId. On SMB 3.0 and 3.0.2, one client's SMB2_GLOBAL_CAP_ENCRYPTION
is ORed into the static per-dialect table and changes how every later
session of that dialect is set up, until the module is reloaded.

The consequence is that a man-in-the-middle between a client and ksmbd
can inject requests into an authenticated session and have them run
with the victim's credentials, and that an NTLM relay to ksmbd is not
stopped by either setting, which is what the two settings exist for.

Patch 1 gives each connection its own copy of its dialect's capability
table. Patch 2 makes the request gate honour sess->sign_required. Patch
3 refuses a binding SESSION_SETUP without a SessionId. Patch 4 refuses
plaintext requests on sessions that were told to encrypt. Patch 5 fails
SESSION_SETUP with STATUS_ACCESS_DENIED, as MS-SMB2 3.3.5.5 requires,
when encryption is mandatory and the client cannot encrypt, and fails a
guest login then.

The series is based on ksmbd-for-next 43dc36660aff. Patch 2 uses
sess->sign_required, and patch 4 ksmbd_set_failed_rsp_credits() and the
MessageId check on the failed-session path, from commits queued there.
On mainline 007722b8211f it applies on top of the eight ksmbd-for-next
commits from e1b357794105 ("ksmbd: verify the signature of session
binding requests") to 332ac50e7533 ("ksmbd: account for the credits of
a request on a failed session"). Patch 1 has no dependencies.

Changes in v3, following Namjae's review of v2:

- Patch 5 (v2 4/4) checks what the client offered, as 3.3.5.5 says:
  SMB2_GLOBAL_CAP_ENCRYPTION in the client's NEGOTIATE capabilities on
  SMB 3.0 and 3.0.2, a common cipher on SMB 3.1.1. v2 used
  smb3_encryption_negotiated(), which holds on 3.0 and 3.0.2 whenever
  encryption is mandatory, because init_smb3_0_server() and
  init_smb3_02_server() then set the capability on the server side. An
  SMB 3.0 client that offered no encryption got a session and was only
  stopped at its first plaintext request; it now fails the first
  SESSION_SETUP.

- Patch 4 (v2 3/4) handles a refused plaintext request like a request
  on a failed session: the request is verified first, which consumes
  its MessageId and refuses a replay, and its credits are charged and
  new ones granted before the response is sent. In v2 a refused
  request did neither: 600 plaintext ECHOs on a session that must
  encrypt were answered with no credits and left their MessageIds
  unconsumed, and ksmbd dropped the connection at the client's next,
  encrypted, request. With v3 the same 600 requests get their credits
  and the next encrypted request succeeds. A plaintext CANCEL
  is still dropped without a response and consumes no credit.

- Guest sessions: with mandatory encryption a guest login reached the
  encryption setup, the response carried SMB2_SESSION_FLAG_ENCRYPT_DATA
  instead of SMB2_SESSION_FLAG_IS_GUEST, the keys were derived from an
  all-zero session key, and v2 also set sess->enc_required on it. A
  guest login got such a session with and without v2, and requests
  encrypted with keys derived from a zero key were accepted on it.
  3.3.5.5.3 derives encryption keys only for a session that is neither
  guest nor anonymous, so a guest session cannot meet the setting;
  patch 5 now fails a guest login with STATUS_ACCESS_DENIED when
  encryption is mandatory, as Samba does.

- New patch 3: smb2_sess_setup() treats SessionId 0 as a new session
  and clears conn->binding, but ntlm_authenticate() and
  krb5_authenticate() looked at the request's
  SMB2_SESSION_REQ_FLAG_BINDING bit to skip the encryption setup. With
  NTLM, the challenge stays on the connection, so after the pending
  session of the first leg has failed, an AUTHENTICATE sent with
  SessionId 0 and the binding bit set up a new session without
  encryption keys and without SMB2_SESSION_FLAG_ENCRYPT_DATA, and an
  unsigned plaintext TREE_CONNECT on it succeeded, with and without
  v2. Patch 3 fails such a request with STATUS_INVALID_PARAMETER, as
  Samba does, and both authentication paths use conn->binding. On
  every other path that reaches them, conn->binding and the bit agree.

- Stable: patch 2's prerequisite tags name the current ksmbd-for-next
  ids of the three commits; patch 4 now also names ac68edfa99c7 and
  332ac50e7533 as prerequisites.

- Tested-by kept on patches 1 and 2, whose code is unchanged since v1.
  Patch 3 is new and patches 4 and 5 have changed; they carry none.

The v2 changes (order, stable tags, v1 3/4 replaced by the
SESSION_SETUP check, CANCEL, Sashiko's four points) are described in
the v2 cover letter.

v2: https://lore.kernel.org/linux-cifs/cover.1795701726.git.research@rootsys.at/
v1: https://lore.kernel.org/linux-cifs/20261119103805.29514-1-research@rootsys.at/

Testing: W=1 builds of fs/smb/server after each patch, with
CONFIG_SMB_SERVER=y and CONFIG_SMB_SERVER_KERBEROS5=y, give no warnings.
checkpatch --strict reports no errors or warnings, only CamelCase
checks for the MS-SMB2 field names SessionId and SessionFlags. On KASAN
kernels built from ksmbd-for-next 43dc36660aff and from mainline
007722b8211f with the eight commits above, each with this series:

- every unsigned or plaintext request that gets through on the
  unpatched tree is refused with STATUS_ACCESS_DENIED: TREE_CONNECT
  after an NTLM login over SMB 3.1.1 with a cipher offered (mandatory
  signing, and mandatory encryption), and over SMB 3.0 after another
  client offered SMB2_GLOBAL_CAP_ENCRYPTION;
- under mandatory encryption, SMB 2.1 clients, SMB 3.0 clients without
  SMB2_GLOBAL_CAP_ENCRYPTION, SMB 3.1.1 clients that offer no cipher
  and guest logins fail SESSION_SETUP with STATUS_ACCESS_DENIED, and an
  AUTHENTICATE with SessionId 0 and the binding bit fails with
  STATUS_INVALID_PARAMETER;
- 600 refused plaintext requests are granted credits, and an encrypted
  request after them succeeds;
- the next NEGOTIATE no longer advertises a capability another client
  offered;
- an unsigned plaintext CANCEL for a request that is not pending gets
  no response on a session that must encrypt; on a session that
  requires signing it gets STATUS_ACCESS_DENIED;
- on a session that must encrypt, a plaintext request is refused with
  STATUS_ACCESS_DENIED whether its TreeId is valid or not, an unsigned
  plaintext reauthentication is refused and the session stays usable,
  and the response to an encrypted reauthentication carries
  SMB2_SESSION_FLAG_ENCRYPT_DATA;
- in a plaintext compound, after the SESSION_SETUP that completes a
  session, an ECHO with SessionId 0 and a SESSION_SETUP for a new
  session are processed as without the series, and a related ECHO is
  refused;
- the in-kernel cifs client mounts, writes and reads under mandatory
  signing with vers=2.1, 3.0, 3.0.2 and 3.1.1 using sign, and with
  vers=3.0, 3.0.2 and 3.1.1 using seal; under mandatory encryption with
  vers=3.0, 3.0.2 and 3.1.1, sign or seal. vers=2.1 under mandatory
  encryption fails at SESSION_SETUP with STATUS_ACCESS_DENIED, as
  intended. A vers=3.1.1 mount without "seal" under mandatory
  encryption keeps working across a server restart.

No KASAN, UBSAN or WARN reports. Not tested: Kerberos sessions
(krb5_authenticate() gets the same changes as ntlm_authenticate() in
patches 3 and 4), SMB Direct, multichannel binding, and a signed
plaintext CANCEL on a session that must encrypt.

We found this with AI-assisted code review and testing; the reproducer
and the fix were tested by us on current mainline.

RootSys GmbH Research (5):
  ksmbd: keep negotiated capabilities per connection
  ksmbd: require signing on sessions that negotiated encryption
  ksmbd: refuse a binding request without a SessionId
  ksmbd: reject plaintext requests on sessions that must be encrypted
  ksmbd: refuse session setup without encryption when it is mandatory

 fs/smb/server/connection.h        |  2 ++
 fs/smb/server/mgmt/user_session.h |  2 ++
 fs/smb/server/server.c            | 51 ++++++++++++++++++++++++--
 fs/smb/server/smb2ops.c           | 19 +++++++---
 fs/smb/server/smb2pdu.c           | 60 +++++++++++++++++++++++++++----
 5 files changed, 121 insertions(+), 13 deletions(-)


base-commit: 43dc36660aff09d415b2949d3498c94763798b21
-- 
2.43.0


             reply	other threads:[~2026-12-04  6:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  6:53 RootSys GmbH Research [this message]
2026-12-04  6:53 ` [PATCH v3 1/5] ksmbd: keep negotiated capabilities per connection RootSys GmbH Research
2026-12-04  6:53 ` [PATCH v3 2/5] ksmbd: require signing on sessions that negotiated encryption RootSys GmbH Research
2026-12-04  6:53 ` [PATCH v3 3/5] ksmbd: refuse a binding request without a SessionId RootSys GmbH Research
2026-12-04  6:53 ` [PATCH v3 4/5] ksmbd: reject plaintext requests on sessions that must be encrypted RootSys GmbH Research
2026-12-04  6:53 ` [PATCH v3 5/5] ksmbd: refuse session setup without encryption when it is mandatory RootSys GmbH Research
2026-12-04 10:04 ` [PATCH v3 0/5] ksmbd: enforce mandatory signing and encryption on requests mixalhs
2026-12-04 10:54   ` RootSys GmbH Research

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1796365947.git.research@rootsys.at \
    --to=team@rootsys.at \
    --cc=chenxiaosong@chenxiaosong.com \
    --cc=icb@fastmail.org \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=mike.michalo@gmail.com \
    --cc=research@rootsys.at \
    --cc=senozhatsky@chromium.org \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox