Skip to contentSkip to conversation

net/smc: fixes 2020-10-14

PATCH In review Karsten Graul 2 participants 5 messages Oct 14, 2020 – Oct 15, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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().

Fixes 555da9af827d ("net/smc: add event-based llc_flow framework")
---
 net/smc/smc_llc.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
net/smc/smc_llc.c +5 -8
index 2db967f2fb50..39039a82f24f 100644
@@ -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
#2 lore raw

PATCH 2/3 net/smc: fix valid DMBE buffer sizes

In reply to Karsten Graul

The 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.

Fixes c6ba7c9ba43d ("net/smc: add base infrastructure for SMC-D and ISM")
---
 net/smc/smc_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/smc/smc_core.c +1 -1
index f1dbb5025c0b..5de637472a11 100644
@@ -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
#3 lore raw

PATCH 3/3 net/smc: fix invalid return code in smcd_new_buf_create()

In reply to Karsten Graul

smc_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().

Fixes 72b7f6c48708 ("net/smc: unique reason code for exceeded max dmb count")
---
 net/smc/smc_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/smc/smc_core.c +2 -1
index 5de637472a11..d790c43c473f 100644
@@ -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
maintainer
#4 lore raw
In reply to Karsten Graul
Quoted 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!