smc: fix out of bound access in smc_nl_get_sys_info()
Jakub Kicinski
maintainerPATCH 1/1 smc: fix out of bound access in smc_nl_get_sys_info()
smc_clc_get_hostname() sets the host pointer to a buffer which is not NULL-terminated (see smc_clc_init()).
Reported-by [email protected]
Fixes 099b990bd11a ("net/smc: Add support for obtaining system information")
Signed-off-by Jakub Kicinski <[email protected]>
--- net/smc/smc_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/smc/smc_core.c +2 -1
@@ -246,7 +246,8 @@ int smc_nl_get_sys_info(struct sk_buff *skb, struct netlink_callback *cb) goto errattr;smc_clc_get_hostname (&host);if (host) { -snprintf (hostname,sizeof (hostname),"%s" , host); +memcpy (hostname, host,SMC_MAX_HOSTNAME_LEN ); + hostname[SMC_MAX_HOSTNAME_LEN ] =0 ;if (nla_put_string (skb,SMC_NLA_SYS_LOCAL_HOST , hostname)) goto errattr; }
Signature · 1 line
2.26.2
Thank you Jakub,
this patch solves the out of bounds access due to snprintf() copying size bytes first and overwriting the last byte with null afterwards.
We will include your patch in our next series for the net tree soon.
Reviewed-by Karsten Graul <[email protected]>
Quoted 25 lines · Jakub Kicinski
smc_clc_get_hostname()sets the host pointer to a buffer which is not NULL-terminated (seesmc_clc_init()).Reported-by [email protected]Fixes 099b990bd11a ("net/smc: Add support for obtaining system information")Signed-off-by Jakub Kicinski <[email protected]>--- net/smc/smc_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/smc/smc_core.c +2
-1@@ -246,7 +246,8 @@ int smc_nl_get_sys_info(struct sk_buff *skb, struct netlink_callback *cb) goto errattr;smc_clc_get_hostname (&host);if (host) { -snprintf (hostname,sizeof (hostname),"%s" , host); +memcpy (hostname, host,SMC_MAX_HOSTNAME_LEN ); + hostname[SMC_MAX_HOSTNAME_LEN ] =0 ;if (nla_put_string (skb,SMC_NLA_SYS_LOCAL_HOST , hostname)) goto errattr; }
Signature · 3 lines
Karsten (I'm a dude)