net/smc: Prevent kernel-infoleak in __smc_diag_dump()
PATCH 1/1 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().
---
Reference: https://lwn.net/Articles/417989/
$ pahole -C "smcd_diag_dmbinfo" net/smc/smc_diag.o
struct smcd_diag_dmbinfo {
__u32 linkid; /* 0 4 *//* XXX 4 bytes hole, try to pack */ __u64 peer_gid __attribute__((__aligned__(8))); /* 8 8 */ __u64 my_gid __attribute__((__aligned__(8))); /* 16 8 */ __u64 token __attribute__((__aligned__(8))); /* 24 8 */ __u64 peer_token __attribute__((__aligned__(8))); /* 32 8 */ /* size: 40, cachelines: 1, members: 5 */ /* sum members: 36, holes: 1, sum holes: 4 */ /* forced alignments: 4, forced holes: 1, sum forced holes: 4 */ /* last cacheline: 40 bytes */ } __attribute__((__aligned__(8))); $ _
net/smc/smc_diag.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
net/smc/smc_diag.c +9 -7
@@ -170,13 +170,15 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb, (req->diag_ext & (1 << (SMC_DIAG_DMBINFO - 1))) && !list_empty(&smc->conn.lgr->list)) {struct smc_connection *conn = &smc->conn; -struct smcd_diag_dmbinfo dinfo = { - .linkid = *((u32 *)conn->lgr->id), - .peer_gid = conn->lgr->peer_gid, - .my_gid = conn->lgr->smcd->local_gid, - .token = conn->rmb_desc->token, - .peer_token = conn->peer_token - }; +struct smcd_diag_dmbinfo dinfo; + +memset (&dinfo,0 ,sizeof (dinfo)); + + dinfo.linkid = *((u32 *)conn->lgr->id); + dinfo.peer_gid = conn->lgr->peer_gid; + dinfo.my_gid = conn->lgr->smcd->local_gid; + dinfo.token = conn->rmb_desc->token; + dinfo.peer_token = conn->peer_token;if (nla_put (skb,SMC_DIAG_DMBINFO ,sizeof (dinfo), &dinfo) <0 ) goto errout;
Signature · 1 line
2.25.1
Quoted 16 lines · Peilin Ye
__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 ofstruct smcd_diag_dmbinfo. Fix it by initializingdinfowithmemset().Fixes 4b1b7d3b30a6 ("net/smc: add SMC-D diag support")Suggested-by Dan Carpenter <[email protected]>Signed-off-by Peilin Ye <[email protected]>---
Reference: https://lwn.net/Articles/417989/$ pahole -C "smcd_diag_dmbinfo" net/smc/smc_diag.o struct smcd_diag_dmbinfo { __u32 linkid; /* 0 4 */
Quoted 14 lines
/* XXX 4 bytes hole, try to pack */ __u64 peer_gid __attribute__((__aligned__(8))); /* 8 8 */ __u64 my_gid __attribute__((__aligned__(8))); /* 16 8 */ __u64 token __attribute__((__aligned__(8))); /* 24 8 */ __u64 peer_token __attribute__((__aligned__(8))); /* 32 8 */ /* size: 40, cachelines: 1, members: 5 */ /* sum members: 36, holes: 1, sum holes: 4 */ /* forced alignments: 4, forced holes: 1, sum forced holes: 4 */ /* last cacheline: 40 bytes */ } __attribute__((__aligned__(8))); $ _
Thanks, patch is added to our local library and will be part of our next shipment of smc patches for the net-tree.
Regards, Ursula
Quoted 21 lines
net/smc/smc_diag.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)net/smc/smc_diag.c +2
-7@@ -170,13 +170,15 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb, (req->diag_ext & (1 << (SMC_DIAG_DMBINFO - 1))) && !list_empty(&smc->conn.lgr->list)) {struct smc_connection *conn = &smc->conn; -struct smcd_diag_dmbinfo dinfo = { - .linkid = *((u32 *)conn->lgr->id), - .peer_gid = conn->lgr->peer_gid, - .my_gid = conn->lgr->smcd->local_gid, - .token = conn->rmb_desc->token, - .peer_token = conn->peer_token - }; +struct smcd_diag_dmbinfo dinfo; +
net/smc/smc_diag.c static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb, · line 184
Quoted 10 lines
net/smc/smc_diag.c +7
-0+memset (&dinfo,0 ,sizeof (dinfo)); + + dinfo.linkid = *((u32 *)conn->lgr->id); + dinfo.peer_gid = conn->lgr->peer_gid; + dinfo.my_gid = conn->lgr->smcd->local_gid; + dinfo.token = conn->rmb_desc->token; + dinfo.peer_token = conn->peer_token;if (nla_put (skb,SMC_DIAG_DMBINFO ,sizeof (dinfo), &dinfo) <0 ) goto errout;
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees