All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] cxl: Fix allowing bogus AFU descriptors with 0 maximum processes
@ 2016-06-29 12:16 Ian Munsie
  2016-06-29 12:16 ` [PATCH 2/2] cxl: Fix allocating a minimum of 2 pages for the SPA Ian Munsie
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Ian Munsie @ 2016-06-29 12:16 UTC (permalink / raw)
  To: Michael Ellerman, mikey, linuxppc-dev, Frederic Barrat, Huy Nguyen
  Cc: Ian Munsie

From: Ian Munsie <imunsie@au1.ibm.com>

If the AFU descriptor of an AFU directed AFU indicates that it supports
0 maximum processes, we will accept that value and attempt to use it.
The SPA will still be allocated (with 2 pages due to another minor bug
and room for 958 processes), and when a context is allocated we will
pass the value of 0 to idr_alloc as the maximum. However, idr_alloc will
treat that as meaning no maximum and will allocate a context number and
we return a valid context.

Conceivably, this could lead to a buffer overflow of the SPA if more
than 958 contexts were allocated, however this is mitigated by the fact
that there are no known AFUs in the wild with a bogus AFU descriptor
like this, and that only the root user is allowed to flash an AFU image
to a card.

Add a check when validating the AFU descriptor to reject any with 0
maximum processes.

We do still allow a dedicated process only AFU to indicate that it
supports 0 contexts even though that is forbidden in the architecture,
as in that case we ignore the value and use 1 instead. This is just on
the off-chance that such a dedicated process AFU may exist (not that I
am aware of any), since their developers are less likely to have cared
about this value at all.

Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
---
 drivers/misc/cxl/pci.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
index 648817a..58d7d821 100644
--- a/drivers/misc/cxl/pci.c
+++ b/drivers/misc/cxl/pci.c
@@ -775,6 +775,21 @@ static int cxl_afu_descriptor_looks_ok(struct cxl_afu *afu)
 		}
 	}
 
+	if ((afu->modes_supported & ~CXL_MODE_DEDICATED) && afu->max_procs_virtualised == 0) {
+		/*
+		 * We could also check this for the dedicated process model
+		 * since the architecture indicates it should be set to 1, but
+		 * in that case we ignore the value and I'd rather not risk
+		 * breaking any existing dedicated process AFUs that left it as
+		 * 0 (not that I'm aware of any). It is clearly an error for an
+		 * AFU directed AFU to set this to 0, and would have previously
+		 * triggered a bug resulting in the maximum not being enforced
+		 * at all since idr_alloc treats 0 as no maximum.
+		 */
+		dev_err(&afu->dev, "AFU does not support any processes\n");
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
-- 
2.8.1

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

end of thread, other threads:[~2016-07-11 10:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-29 12:16 [PATCH 1/2] cxl: Fix allowing bogus AFU descriptors with 0 maximum processes Ian Munsie
2016-06-29 12:16 ` [PATCH 2/2] cxl: Fix allocating a minimum of 2 pages for the SPA Ian Munsie
2016-06-29 16:06   ` Frederic Barrat
2016-06-29 23:07   ` Andrew Donnellan
2016-07-11 10:19   ` [2/2] " Michael Ellerman
2016-06-29 16:06 ` [PATCH 1/2] cxl: Fix allowing bogus AFU descriptors with 0 maximum processes Frederic Barrat
2016-06-29 22:35 ` Andrew Donnellan
2016-07-11 10:19 ` [1/2] " Michael Ellerman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.