RDMA/rtrs: guard against null kobj name
Subsystems (2)
PATCH 1/1 RDMA/rtrs: guard against null kobj name
In the client, if init_path() errors, the callee tries to clean up with rtrs_clt_close_conns(). However, this can lead to calling the event tracing code with clt_path->kobj->name being NULL and thus causing a null pointer dereference when trying to copy from it.
This just adds a guard to check that the name is not NULL before copying from it. The server appears to have a similar pattern.
--- drivers/infiniband/ulp/rtrs/rtrs-clt-trace.h | 2 +- drivers/infiniband/ulp/rtrs/rtrs-srv-trace.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-clt-trace.h +1 -1
@@ -55,7 +55,7 @@ DECLARE_EVENT_CLASS(rtrs_clt_conn_class, __entry->max_reconnect_attempts = clt->max_reconnect_attempts; __entry->fail_cnt = clt_path->stats->reconnects.fail_cnt; __entry->success_cnt = clt_path->stats->reconnects.successful_cnt; -memcpy (__entry->sessname,kobject_name (&clt_path->kobj),NAME_MAX ); +strscpy (__entry->sessname,kobject_name (&clt_path->kobj) ?:"" ,NAME_MAX ); ), TP_printk("RTRS-CLT: sess='%s' state=%s attempts='%d' max-attempts='%d' fail='%d' success='%d'",
drivers/infiniband/ulp/rtrs/rtrs-srv-trace.h +1 -1
@@ -61,7 +61,7 @@ TRACE_EVENT(send_io_resp_imm, __entry->msg_id = id->msg_id; __entry->wr_cnt =atomic_read (&con->c.wr_cnt); __entry->signal_interval = s->signal_interval; -memcpy (__entry->sessname,kobject_name (&srv_path->kobj),NAME_MAX ); +strscpy (__entry->sessname,kobject_name (&srv_path->kobj) ?:"" ,NAME_MAX ); ), TP_printk("sess='%s' state='%s' dir=%s err='%d' inval='%d' glob-inval='%d' msgid='%u' wrcnt='%d' sig-interval='%u'",
Signature · 1 line
2.55.0
Quoted 6 lines · Ryan Mehri
In the client, if
init_path()errors, the callee tries to clean up withrtrs_clt_close_conns(). However, this can lead to calling the event tracing code withclt_path->kobj->namebeingNULLand thus causing a null pointer dereference when trying to copy from it.
Quoted 8 lines
This just adds a guard to check that the name is not
NULLbefore copying from it. The server appears to have a similar pattern.Fixes 5a93929d9f9a1 ("RDMA/rtrs-clt: Add event tracing support")Fixes c16762b7bf54d ("RDMA/rtrs-srv: Add event tracing support")Reported-by [email protected]Signed-off-by Ryan Mehri <[email protected]>
lgtm, thx!
Quoted 34 lines
--- drivers/infiniband/ulp/rtrs/rtrs-clt-trace.h | 2 +- drivers/infiniband/ulp/rtrs/rtrs-srv-trace.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/infiniband/ulp/rtrs/rtrs-clt-trace.h +1
-1@@ -55,7 +55,7 @@ DECLARE_EVENT_CLASS(rtrs_clt_conn_class, __entry->max_reconnect_attempts = clt->max_reconnect_attempts; __entry->fail_cnt = clt_path->stats->reconnects.fail_cnt; __entry->success_cnt = clt_path->stats->reconnects.successful_cnt; -memcpy (__entry->sessname,kobject_name (&clt_path->kobj),NAME_MAX ); +strscpy (__entry->sessname,kobject_name (&clt_path->kobj) ?:"" ,NAME_MAX ); ), TP_printk("RTRS-CLT: sess='%s' state=%s attempts='%d' max-attempts='%d' fail='%d' success='%d'",drivers/infiniband/ulp/rtrs/rtrs-srv-trace.h +1
-2@@ -61,7 +61,7 @@ TRACE_EVENT(send_io_resp_imm, __entry->msg_id = id->msg_id; __entry->wr_cnt =atomic_read (&con->c.wr_cnt); __entry->signal_interval = s->signal_interval; -memcpy (__entry->sessname,kobject_name (&srv_path->kobj),NAME_MAX ); +strscpy (__entry->sessname,kobject_name (&srv_path->kobj) ?:"" ,NAME_MAX ); ), TP_printk("sess='%s' state='%s' dir=%s err='%d' inval='%d' glob-inval='%d' msgid='%u' wrcnt='%d' sig-interval='%u'", --2.55.0
Leon Romanovsky
AppliedQuoted 9 lines · Ryan Mehri
In the client, if
init_path()errors, the callee tries to clean up withrtrs_clt_close_conns(). However, this can lead to calling the event tracing code withclt_path->kobj->namebeingNULLand thus causing a null pointer dereference when trying to copy from it.This just adds a guard to check that the name is not
NULLbefore copying from it. The server appears to have a similar pattern.[...]
Applied, thanks!
[1/1] RDMA/rtrs: guard against null kobj name
https://git.kernel.org/rdma/rdma/c/99c24a8968ebef
Best regards,
Signature · 1 line
Leon Romanovsky <[email protected]>