net/smc: fixes 2020-10-14
cover net/smc: fixes 2020-10-14
Please apply the following patch series for smc to netdev's net tree.
The first patch fixes a possible use-after-free of delayed llc events. Patch 2 corrects the number of DMB buffer sizes. And patch 3 ensures a correctly formatted return code when smc_ism_register_dmb() fails to create a new DMB.
Karsten Graul (3):
net/smc: fix use-after-free of delayed events net/smc: fix valid DMBE buffer sizes
net/smc: fix invalid return code in smcd_new_buf_create()
net/smc/smc_core.c | 5 +++-- net/smc/smc_llc.c | 13 +++++-------- 2 files changed, 8 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 net/smc: fix use-after-free of delayed events
When a delayed event is enqueued then the event worker will send this event the next time it is running and no other flow is currently active. The event handler is called for the delayed event, and the pointer to the event keeps set in lgr->delayed_event. This pointer is cleared later in the processing by smc_llc_flow_start(). This can lead to a use-after-free condition when the processing does not reach smc_llc_flow_start(), but frees the event because of an error situation. Then the delayed_event pointer is still set but the event is freed.
Fix this by always clearing the delayed event pointer when the event is provided to the event handler for processing, and remove the code to clear it in smc_llc_flow_start().
--- net/smc/smc_llc.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
net/smc/smc_llc.c +5 -8
@@ -233,8 +233,6 @@ static bool smc_llc_flow_start(struct smc_llc_flow *flow,default : flow->type =SMC_LLC_FLOW_NONE ; } -if (qentry == lgr->delayed_event) - lgr->delayed_event =NULL ;smc_llc_flow_qentry_set (flow, qentry);spin_unlock_bh (&lgr->llc_flow_lock);return true;
@@ -1603,13 +1601,12 @@ static void smc_llc_event_work(struct work_struct *work)struct smc_llc_qentry *qentry;if (!lgr->llc_flow_lcl.type && lgr->delayed_event) { -if (smc_link_usable (lgr->delayed_event->link)) { -smc_llc_event_handler (lgr->delayed_event); - }else { - qentry = lgr->delayed_event; - lgr->delayed_event =NULL ; + qentry = lgr->delayed_event; + lgr->delayed_event =NULL ; +if (smc_link_usable (qentry->link)) +smc_llc_event_handler (qentry); +else kfree (qentry); - } } again:
Signature · 1 line
2.17.1
PATCH 3/3 net/smc: fix invalid return code in smcd_new_buf_create()
In reply to Karsten Graulsmc_ism_register_dmb() returns error codes set by the ISM driver which are not guaranteed to be negative or in the errno range. Such values would not be handled by ERR_PTR() and finally the return code will be used as a memory address.
Fix that by using a valid negative errno value with ERR_PTR().
--- net/smc/smc_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/smc/smc_core.c +2 -1
@@ -1615,7 +1615,8 @@ static struct smc_buf_desc *smcd_new_buf_create(struct smc_link_group *lgr, rc =smc_ism_register_dmb (lgr, bufsize, buf_desc);if (rc) {kfree (buf_desc); -return (rc == -ENOMEM ) ?ERR_PTR (-EAGAIN ) :ERR_PTR (rc); +return (rc == -ENOMEM ) ?ERR_PTR (-EAGAIN ) : +ERR_PTR (-EIO ); } buf_desc->pages =virt_to_page (buf_desc->cpu_addr);/* CDC header stored in buf. So, pretend it was smaller */
Signature · 1 line
2.17.1
PATCH 2/3 net/smc: fix valid DMBE buffer sizes
In reply to Karsten GraulThe SMCD_DMBE_SIZES should include all valid DMBE buffer sizes, so the correct value is 6 which means 1MB. With 7 the registration of an ISM buffer would always fail because of the invalid size requested. Fix that and set the value to 6.
--- net/smc/smc_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/smc/smc_core.c +1 -1
@@ -1596,7 +1596,7 @@ static int smcr_buf_map_usable_links(struct smc_link_group *lgr,return rc; } -#define SMCD_DMBE_SIZES 7/* 0 -> 16KB, 1 -> 32KB, .. 6 -> 1MB */ +#define SMCD_DMBE_SIZES 6/* 0 -> 16KB, 1 -> 32KB, .. 6 -> 1MB */ static struct smc_buf_desc *smcd_new_buf_create (struct smc_link_group *lgr,bool is_dmb,int bufsize)
Signature · 1 line
2.17.1
Jakub Kicinski
maintainerQuoted 6 lines · On Wed, 14 Oct 2020 19:43:26 +0200 Karsten Graul wrote:
Please apply the following patch series for smc to netdev's net tree.
The first patch fixes a possible use-after-free of delayed llc events. Patch 2 corrects the number of DMB buffer sizes. And patch 3 ensures a correctly formatted return code when
smc_ism_register_dmb()fails to create a new DMB.
Applied and queued for stable, thanks!