Skip to content
Open
7 changes: 6 additions & 1 deletion drivers/hid/hid-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,12 @@ EXPORT_SYMBOL_GPL(hid_snto32);

static u32 s32ton(__s32 value, unsigned n)
{
s32 a = value >> (n - 1);
s32 a;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original commit does not have a empty line here. Not sure what happened. What that a clean cherry pick? I tried it myself and I had conflicts.

if (!value || !n)
return 0;

a = value >> (n - 1);
if (a && a != -1)
return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
return value & ((1 << n) - 1);
Expand Down
12 changes: 6 additions & 6 deletions fs/cifs/cifsencrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
unlock:
Copy link
Collaborator

@PlaidCat PlaidCat Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cherry-pick went Bananas here
dbc0be4

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I tried locally because I was curious how this happened, and my cherry pick does not contain all these extra things here. Not sure what happened there.

cifs_server_unlock(ses->server);
setup_ntlmv2_rsp_ret:
kfree(tiblob);
kfree_sensitive(tiblob);

return rc;
}
Expand Down Expand Up @@ -753,14 +753,14 @@ cifs_crypto_secmech_release(struct TCP_Server_Info *server)
server->secmech.ccmaesdecrypt = NULL;
}

kfree(server->secmech.sdesccmacaes);
kfree_sensitive(server->secmech.sdesccmacaes);
server->secmech.sdesccmacaes = NULL;
kfree(server->secmech.sdeschmacsha256);
kfree_sensitive(server->secmech.sdeschmacsha256);
server->secmech.sdeschmacsha256 = NULL;
kfree(server->secmech.sdeschmacmd5);
kfree_sensitive(server->secmech.sdeschmacmd5);
server->secmech.sdeschmacmd5 = NULL;
kfree(server->secmech.sdescmd5);
kfree_sensitive(server->secmech.sdescmd5);
server->secmech.sdescmd5 = NULL;
kfree(server->secmech.sdescsha512);
kfree_sensitive(server->secmech.sdescsha512);
server->secmech.sdescsha512 = NULL;
}
6 changes: 3 additions & 3 deletions fs/cifs/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ cifs_abort_connection(struct TCP_Server_Info *server)
}
server->sequence_number = 0;
server->session_estab = false;
kfree(server->session_key.response);
kfree_sensitive(server->session_key.response);
server->session_key.response = NULL;
server->session_key.len = 0;
server->lstrp = jiffies;
Expand Down Expand Up @@ -1562,7 +1562,7 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect)

cifs_crypto_secmech_release(server);

kfree(server->session_key.response);
kfree_sensitive(server->session_key.response);
server->session_key.response = NULL;
server->session_key.len = 0;
kfree(server->hostname);
Expand Down Expand Up @@ -4097,7 +4097,7 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,
if (ses->auth_key.response) {
cifs_dbg(FYI, "Free previous auth_key.response = %p\n",
ses->auth_key.response);
kfree(ses->auth_key.response);
kfree_sensitive(ses->auth_key.response);
ses->auth_key.response = NULL;
ses->auth_key.len = 0;
}
Expand Down
12 changes: 10 additions & 2 deletions fs/cifs/fs_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,13 @@ do { \
cifs_sb->ctx->field = NULL; \
} while (0)

#define STEAL_STRING_SENSITIVE(cifs_sb, ctx, field) \
do { \
kfree_sensitive(ctx->field); \
ctx->field = cifs_sb->ctx->field; \
cifs_sb->ctx->field = NULL; \
} while (0)

static int smb3_reconfigure(struct fs_context *fc)
{
struct smb3_fs_context *ctx = smb3_fc2context(fc);
Expand All @@ -809,7 +816,7 @@ static int smb3_reconfigure(struct fs_context *fc)
STEAL_STRING(cifs_sb, ctx, UNC);
STEAL_STRING(cifs_sb, ctx, source);
STEAL_STRING(cifs_sb, ctx, username);
STEAL_STRING(cifs_sb, ctx, password);
STEAL_STRING_SENSITIVE(cifs_sb, ctx, password);
STEAL_STRING(cifs_sb, ctx, domainname);
STEAL_STRING(cifs_sb, ctx, nodename);
STEAL_STRING(cifs_sb, ctx, iocharset);
Expand Down Expand Up @@ -1150,7 +1157,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
}
break;
case Opt_pass:
kfree(ctx->password);
kfree_sensitive(ctx->password);
ctx->password = NULL;
if (strlen(param->string) == 0)
break;
Expand Down Expand Up @@ -1458,6 +1465,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
return 0;

cifs_parse_mount_err:
kfree_sensitive(ctx->password);
return -EINVAL;
}

Expand Down
2 changes: 1 addition & 1 deletion fs/cifs/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ cifs_alloc_hash(const char *name,
void
cifs_free_hash(struct crypto_shash **shash, struct sdesc **sdesc)
{
kfree(*sdesc);
kfree_sensitive(*sdesc);
*sdesc = NULL;
if (*shash)
crypto_free_shash(*shash);
Expand Down
24 changes: 15 additions & 9 deletions fs/cifs/sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,12 @@ sess_alloc_buffer(struct sess_data *sess_data, int wct)
static void
sess_free_buffer(struct sess_data *sess_data)
{
int i;

/* zero the session data before freeing, as it might contain sensitive info (keys, etc) */
for (i = 0; i < 3; i++)
if (sess_data->iov[i].iov_base)
memzero_explicit(sess_data->iov[i].iov_base, sess_data->iov[i].iov_len);

free_rsp_buf(sess_data->buf0_type, sess_data->iov[0].iov_base);
sess_data->buf0_type = CIFS_NO_BUFFER;
Expand Down Expand Up @@ -1372,7 +1378,7 @@ sess_auth_ntlmv2(struct sess_data *sess_data)
sess_data->result = rc;
sess_data->func = NULL;
sess_free_buffer(sess_data);
kfree(ses->auth_key.response);
kfree_sensitive(ses->auth_key.response);
ses->auth_key.response = NULL;
}

Expand Down Expand Up @@ -1511,7 +1517,7 @@ sess_auth_kerberos(struct sess_data *sess_data)
sess_data->result = rc;
sess_data->func = NULL;
sess_free_buffer(sess_data);
kfree(ses->auth_key.response);
kfree_sensitive(ses->auth_key.response);
ses->auth_key.response = NULL;
}

Expand Down Expand Up @@ -1646,7 +1652,7 @@ sess_auth_rawntlmssp_negotiate(struct sess_data *sess_data)
rc = decode_ntlmssp_challenge(bcc_ptr, blob_len, ses);

out_free_ntlmsspblob:
kfree(ntlmsspblob);
kfree_sensitive(ntlmsspblob);
out:
sess_free_buffer(sess_data);

Expand All @@ -1656,9 +1662,9 @@ sess_auth_rawntlmssp_negotiate(struct sess_data *sess_data)
}

/* Else error. Cleanup */
kfree(ses->auth_key.response);
kfree_sensitive(ses->auth_key.response);
ses->auth_key.response = NULL;
kfree(ses->ntlmssp);
kfree_sensitive(ses->ntlmssp);
ses->ntlmssp = NULL;

sess_data->func = NULL;
Expand Down Expand Up @@ -1757,17 +1763,17 @@ sess_auth_rawntlmssp_authenticate(struct sess_data *sess_data)
}

out_free_ntlmsspblob:
kfree(ntlmsspblob);
kfree_sensitive(ntlmsspblob);
out:
sess_free_buffer(sess_data);

if (!rc)
rc = sess_establish_session(sess_data);

/* Cleanup */
kfree(ses->auth_key.response);
kfree_sensitive(ses->auth_key.response);
ses->auth_key.response = NULL;
kfree(ses->ntlmssp);
kfree_sensitive(ses->ntlmssp);
ses->ntlmssp = NULL;

sess_data->func = NULL;
Expand Down Expand Up @@ -1843,7 +1849,7 @@ int CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses,
rc = sess_data->result;

out:
kfree(sess_data);
kfree_sensitive(sess_data);
return rc;
}
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
6 changes: 3 additions & 3 deletions fs/cifs/smb2ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -4390,11 +4390,11 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
if (!rc && enc)
memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);

kfree(iv);
kfree_sensitive(iv);
free_sg:
kfree(sg);
kfree_sensitive(sg);
free_req:
kfree(req);
kfree_sensitive(req);
return rc;
}

Expand Down
19 changes: 14 additions & 5 deletions fs/cifs/smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,13 @@ SMB2_sess_alloc_buffer(struct SMB2_sess_data *sess_data)
static void
SMB2_sess_free_buffer(struct SMB2_sess_data *sess_data)
{
int i;

/* zero the session data before freeing, as it might contain sensitive info (keys, etc) */
for (i = 0; i < 2; i++)
if (sess_data->iov[i].iov_base)
memzero_explicit(sess_data->iov[i].iov_base, sess_data->iov[i].iov_len);

free_rsp_buf(sess_data->buf0_type, sess_data->iov[0].iov_base);
sess_data->buf0_type = CIFS_NO_BUFFER;
}
Expand Down Expand Up @@ -1465,6 +1472,8 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data)
out_put_spnego_key:
key_invalidate(spnego_key);
key_put(spnego_key);
if (rc)
kfree_sensitive(ses->auth_key.response);
out:
sess_data->result = rc;
sess_data->func = NULL;
Expand Down Expand Up @@ -1561,15 +1570,15 @@ SMB2_sess_auth_rawntlmssp_negotiate(struct SMB2_sess_data *sess_data)
}

out:
kfree(ntlmssp_blob);
memzero_explicit(ntlmssp_blob, blob_length);
SMB2_sess_free_buffer(sess_data);
if (!rc) {
sess_data->result = 0;
sess_data->func = SMB2_sess_auth_rawntlmssp_authenticate;
return;
}
out_err:
kfree(ses->ntlmssp);
kfree_sensitive(ses->ntlmssp);
ses->ntlmssp = NULL;
sess_data->result = rc;
sess_data->func = NULL;
Expand Down Expand Up @@ -1645,9 +1654,9 @@ SMB2_sess_auth_rawntlmssp_authenticate(struct SMB2_sess_data *sess_data)
}
#endif
out:
kfree(ntlmssp_blob);
memzero_explicit(ntlmssp_blob, blob_length);
SMB2_sess_free_buffer(sess_data);
kfree(ses->ntlmssp);
kfree_sensitive(ses->ntlmssp);
ses->ntlmssp = NULL;
sess_data->result = rc;
sess_data->func = NULL;
Expand Down Expand Up @@ -1725,7 +1734,7 @@ SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses,
cifs_server_dbg(VFS, "signing requested but authenticated as guest\n");
rc = sess_data->result;
out:
kfree(sess_data);
kfree_sensitive(sess_data);
return rc;
}

Expand Down
31 changes: 22 additions & 9 deletions net/tls/tls_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,9 @@ int decrypt_skb(struct sock *sk, struct scatterlist *sgout)
return tls_decrypt_sg(sk, NULL, sgout, &darg);
}

/* All records returned from a recvmsg() call must have the same type.
* 0 is not a valid content type. Use it as "no type reported, yet".
*/
static int tls_record_content_type(struct msghdr *msg, struct tls_msg *tlm,
u8 *control)
{
Expand Down Expand Up @@ -1751,7 +1754,8 @@ static int process_rx_list(struct tls_sw_context_rx *ctx,
u8 *control,
size_t skip,
size_t len,
bool is_peek)
bool is_peek,
bool *more)
{
struct sk_buff *skb = skb_peek(&ctx->rx_list);
struct tls_msg *tlm;
Expand All @@ -1764,7 +1768,7 @@ static int process_rx_list(struct tls_sw_context_rx *ctx,

err = tls_record_content_type(msg, tlm, control);
if (err <= 0)
goto out;
goto more;

if (skip < rxm->full_len)
break;
Expand All @@ -1782,12 +1786,12 @@ static int process_rx_list(struct tls_sw_context_rx *ctx,

err = tls_record_content_type(msg, tlm, control);
if (err <= 0)
goto out;
goto more;

err = skb_copy_datagram_msg(skb, rxm->offset + skip,
msg, chunk);
if (err < 0)
goto out;
goto more;

len = len - chunk;
copied = copied + chunk;
Expand Down Expand Up @@ -1823,6 +1827,10 @@ static int process_rx_list(struct tls_sw_context_rx *ctx,

out:
return copied ? : err;
more:
if (more)
*more = true;
goto out;
}

static bool
Expand Down Expand Up @@ -1918,6 +1926,7 @@ int tls_sw_recvmsg(struct sock *sk,
int target, err;
bool is_kvec = iov_iter_is_kvec(&msg->msg_iter);
bool is_peek = flags & MSG_PEEK;
bool rx_more = false;
bool released = true;
bool bpf_strp_enabled;
bool zc_capable;
Expand All @@ -1939,12 +1948,14 @@ int tls_sw_recvmsg(struct sock *sk,
goto end;

/* Process pending decrypted records. It must be non-zero-copy */
err = process_rx_list(ctx, msg, &control, 0, len, is_peek);
err = process_rx_list(ctx, msg, &control, 0, len, is_peek, &rx_more);
if (err < 0)
goto end;

/* process_rx_list() will set @control if it processed any records */
copied = err;
if (len <= copied)
if (len <= copied || rx_more ||
(control && control != TLS_RECORD_TYPE_DATA))
goto end;

target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
Expand Down Expand Up @@ -2107,11 +2118,13 @@ int tls_sw_recvmsg(struct sock *sk,
/* Drain records from the rx_list & copy if required */
if (is_peek || is_kvec)
err = process_rx_list(ctx, msg, &control, copied,
decrypted, is_peek);
decrypted, is_peek, NULL);
else
err = process_rx_list(ctx, msg, &control, 0,
async_copy_bytes, is_peek);
decrypted = max(err, 0);
async_copy_bytes, is_peek, NULL);

/* we could have copied less than we wanted, and possibly nothing */
decrypted += max(err, 0) - async_copy_bytes;
}

copied += decrypted;
Expand Down