Skip to content

Commit ce51f63

Browse files
peilin-yedavem330
authored andcommitted
net/smc: Prevent kernel-infoleak in __smc_diag_dump()
__smc_diag_dump() is potentially copying uninitialized kernel stack memory into socket buffers, since the compiler may leave a 4-byte hole near the beginning of `struct smcd_diag_dmbinfo`. Fix it by initializing `dinfo` with memset(). Fixes: 4b1b7d3 ("net/smc: add SMC-D diag support") Suggested-by: Dan Carpenter <[email protected]> Signed-off-by: Peilin Ye <[email protected]> Signed-off-by: Ursula Braun <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3e659a8 commit ce51f63

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

net/smc/smc_diag.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,15 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb,
170170
(req->diag_ext & (1 << (SMC_DIAG_DMBINFO - 1))) &&
171171
!list_empty(&smc->conn.lgr->list)) {
172172
struct smc_connection *conn = &smc->conn;
173-
struct smcd_diag_dmbinfo dinfo = {
174-
.linkid = *((u32 *)conn->lgr->id),
175-
.peer_gid = conn->lgr->peer_gid,
176-
.my_gid = conn->lgr->smcd->local_gid,
177-
.token = conn->rmb_desc->token,
178-
.peer_token = conn->peer_token
179-
};
173+
struct smcd_diag_dmbinfo dinfo;
174+
175+
memset(&dinfo, 0, sizeof(dinfo));
176+
177+
dinfo.linkid = *((u32 *)conn->lgr->id);
178+
dinfo.peer_gid = conn->lgr->peer_gid;
179+
dinfo.my_gid = conn->lgr->smcd->local_gid;
180+
dinfo.token = conn->rmb_desc->token;
181+
dinfo.peer_token = conn->peer_token;
180182

181183
if (nla_put(skb, SMC_DIAG_DMBINFO, sizeof(dinfo), &dinfo) < 0)
182184
goto errout;

0 commit comments

Comments
 (0)