Skip to content

Commit 98d4435

Browse files
name2965davem330
authored andcommitted
net/smc: prevent NULL pointer dereference in txopt_get
Since smc_inet6_prot does not initialize ipv6_pinfo_offset, inet6_create() copies an incorrect address value, sk + 0 (offset), to inet_sk(sk)->pinet6. In addition, since inet_sk(sk)->pinet6 and smc_sk(sk)->clcsock practically point to the same address, when smc_create_clcsk() stores the newly created clcsock in smc_sk(sk)->clcsock, inet_sk(sk)->pinet6 is corrupted into clcsock. This causes NULL pointer dereference and various other memory corruptions. To solve this problem, you need to initialize ipv6_pinfo_offset, add a smc6_sock structure, and then add ipv6_pinfo as the second member of the smc_sock structure. Reported-by: syzkaller <[email protected]> Fixes: d25a92c ("net/smc: Introduce IPPROTO_SMC") Signed-off-by: Jeongjun Park <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1bb3c54 commit 98d4435

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

net/smc/smc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ struct smc_connection {
284284

285285
struct smc_sock { /* smc sock container */
286286
struct sock sk;
287+
#if IS_ENABLED(CONFIG_IPV6)
288+
struct ipv6_pinfo *pinet6;
289+
#endif
287290
struct socket *clcsock; /* internal tcp socket */
288291
void (*clcsk_state_change)(struct sock *sk);
289292
/* original stat_change fct. */

net/smc/smc_inet.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,22 @@ static struct inet_protosw smc_inet_protosw = {
6060
};
6161

6262
#if IS_ENABLED(CONFIG_IPV6)
63+
struct smc6_sock {
64+
struct smc_sock smc;
65+
struct ipv6_pinfo inet6;
66+
};
67+
6368
static struct proto smc_inet6_prot = {
6469
.name = "INET6_SMC",
6570
.owner = THIS_MODULE,
6671
.init = smc_inet_init_sock,
6772
.hash = smc_hash_sk,
6873
.unhash = smc_unhash_sk,
6974
.release_cb = smc_release_cb,
70-
.obj_size = sizeof(struct smc_sock),
75+
.obj_size = sizeof(struct smc6_sock),
7176
.h.smc_hash = &smc_v6_hashinfo,
7277
.slab_flags = SLAB_TYPESAFE_BY_RCU,
78+
.ipv6_pinfo_offset = offsetof(struct smc6_sock, inet6),
7379
};
7480

7581
static const struct proto_ops smc_inet6_stream_ops = {

0 commit comments

Comments
 (0)