netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/3] net/smc: fixes 2020-10-14
@ 2020-10-14 17:43 Karsten Graul
  2020-10-14 17:43 ` [PATCH net 1/3] net/smc: fix use-after-free of delayed events Karsten Graul
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Karsten Graul @ 2020-10-14 17:43 UTC (permalink / raw)
  To: davem; +Cc: netdev, linux-s390, heiko.carstens, raspl, ubraun

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

-- 
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net 1/3] net/smc: fix use-after-free of delayed events
  2020-10-14 17:43 [PATCH net 0/3] net/smc: fixes 2020-10-14 Karsten Graul
@ 2020-10-14 17:43 ` Karsten Graul
  2020-10-14 17:43 ` [PATCH net 2/3] net/smc: fix valid DMBE buffer sizes Karsten Graul
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Karsten Graul @ 2020-10-14 17:43 UTC (permalink / raw)
  To: davem; +Cc: netdev, linux-s390, heiko.carstens, raspl, ubraun

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")
Signed-off-by: Karsten Graul <kgraul@linux.ibm.com>
---
 net/smc/smc_llc.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/net/smc/smc_llc.c b/net/smc/smc_llc.c
index 2db967f2fb50..39039a82f24f 100644
--- a/net/smc/smc_llc.c
+++ b/net/smc/smc_llc.c
@@ -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:
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net 2/3] net/smc: fix valid DMBE buffer sizes
  2020-10-14 17:43 [PATCH net 0/3] net/smc: fixes 2020-10-14 Karsten Graul
  2020-10-14 17:43 ` [PATCH net 1/3] net/smc: fix use-after-free of delayed events Karsten Graul
@ 2020-10-14 17:43 ` Karsten Graul
  2020-10-14 17:43 ` [PATCH net 3/3] net/smc: fix invalid return code in smcd_new_buf_create() Karsten Graul
  2020-10-15 16:59 ` [PATCH net 0/3] net/smc: fixes 2020-10-14 Jakub Kicinski
  3 siblings, 0 replies; 5+ messages in thread
From: Karsten Graul @ 2020-10-14 17:43 UTC (permalink / raw)
  To: davem; +Cc: netdev, linux-s390, heiko.carstens, raspl, ubraun

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")
Signed-off-by: Karsten Graul <kgraul@linux.ibm.com>
---
 net/smc/smc_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index f1dbb5025c0b..5de637472a11 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -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)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net 3/3] net/smc: fix invalid return code in smcd_new_buf_create()
  2020-10-14 17:43 [PATCH net 0/3] net/smc: fixes 2020-10-14 Karsten Graul
  2020-10-14 17:43 ` [PATCH net 1/3] net/smc: fix use-after-free of delayed events Karsten Graul
  2020-10-14 17:43 ` [PATCH net 2/3] net/smc: fix valid DMBE buffer sizes Karsten Graul
@ 2020-10-14 17:43 ` Karsten Graul
  2020-10-15 16:59 ` [PATCH net 0/3] net/smc: fixes 2020-10-14 Jakub Kicinski
  3 siblings, 0 replies; 5+ messages in thread
From: Karsten Graul @ 2020-10-14 17:43 UTC (permalink / raw)
  To: davem; +Cc: netdev, linux-s390, heiko.carstens, raspl, ubraun

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")
Signed-off-by: Karsten Graul <kgraul@linux.ibm.com>
---
 net/smc/smc_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index 5de637472a11..d790c43c473f 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -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 */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net 0/3] net/smc: fixes 2020-10-14
  2020-10-14 17:43 [PATCH net 0/3] net/smc: fixes 2020-10-14 Karsten Graul
                   ` (2 preceding siblings ...)
  2020-10-14 17:43 ` [PATCH net 3/3] net/smc: fix invalid return code in smcd_new_buf_create() Karsten Graul
@ 2020-10-15 16:59 ` Jakub Kicinski
  3 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2020-10-15 16:59 UTC (permalink / raw)
  To: Karsten Graul; +Cc: davem, netdev, linux-s390, heiko.carstens, raspl, ubraun

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!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-10-15 16:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-14 17:43 [PATCH net 0/3] net/smc: fixes 2020-10-14 Karsten Graul
2020-10-14 17:43 ` [PATCH net 1/3] net/smc: fix use-after-free of delayed events Karsten Graul
2020-10-14 17:43 ` [PATCH net 2/3] net/smc: fix valid DMBE buffer sizes Karsten Graul
2020-10-14 17:43 ` [PATCH net 3/3] net/smc: fix invalid return code in smcd_new_buf_create() Karsten Graul
2020-10-15 16:59 ` [PATCH net 0/3] net/smc: fixes 2020-10-14 Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).