Skip to contentSkip to conversation

libfc: sanity check cpu number extracted from xid

PATCH Applied Chris Leech 3 participants 4 messages Jun 30, 2016 – Jul 14, 2016 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 20160630070925.ptbgkeq57txs55gf-3LAbnSA0sDC4fIQPS+WK3rNAH6kLmebB@public.gmane.org

#2 lore raw

PATCH v2 1/1 libfc: sanity check cpu number extracted from xid

In the receive path libfc extracts a cpu number from the ox_id in the fiber channel header and uses that to do a per_cpu_ptr conversion. If, for some reason, a frame is received with an invalid ox_id, per_cpu_ptr will return an invalid pointer and the libfc receive path will panic the system trying to use it.

I'm currently looking at such a case, and I don't yet know why a cpu number > nr_cpu_ids is appearing in an exchange id. But adding a sanity check in libfc prevents a system panic, and seems like good idea when dealing with frames coming in from the network.

---
 drivers/scsi/libfc/fc_exch.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/scsi/libfc/fc_exch.c +9 -1
index 30f9ef0..e72673b 100644
@@ -908,9 +908,17 @@ static struct fc_exch *fc_exch_find(struct fc_exch_mgr *mp, u16 xid)
 {
 	struct fc_exch_pool *pool;
 	struct fc_exch *ep = NULL;
+	u16 cpu = xid & fc_cpu_mask;
+
+	if (cpu >= nr_cpu_ids || !cpu_possible(cpu)) {
+		printk_ratelimited(KERN_ERR
+			"libfc: lookup request for XID = %d, "
+			"indicates invalid CPU %d\n", xid, cpu);
+		return NULL;
+	}
 
 	if ((xid >= mp->min_xid) && (xid <= mp->max_xid)) {
-		pool = per_cpu_ptr(mp->pool, xid & fc_cpu_mask);
+		pool = per_cpu_ptr(mp->pool, cpu);
 		spin_lock_bh(&pool->lock);
 		ep = fc_exch_ptr_get(pool, (xid - mp->min_xid) >> fc_cpu_order);
 		if (ep) {
Signature · 1 line
2.5.5

A message that is not in the archive (sent off-list or not yet received): 1467300756-7949-1-git-send-email-cleech-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#4 lore raw
Quoted 29 lines · Chris Leech

In the receive path libfc extracts a cpu number from the ox_id in the fiber channel header and uses that to do a per_cpu_ptr conversion. If, for some reason, a frame is received with an invalid ox_id, per_cpu_ptr will return an invalid pointer and the libfc receive path will panic the system trying to use it.

I'm currently looking at such a case, and I don't yet know why a cpu number > nr_cpu_ids is appearing in an exchange id. But adding a sanity check in libfc prevents a system panic, and seems like good idea when dealing with frames coming in from the network.

---
 drivers/scsi/libfc/fc_exch.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/scsi/libfc/fc_exch.c +5 -0
index 30f9ef0..e72673b 100644
@@ -908,9 +908,17 @@ static struct fc_exch *fc_exch_find(struct fc_exch_mgr *mp, u16 xid)
 {
 	struct fc_exch_pool *pool;
 	struct fc_exch *ep = NULL;
+	u16 cpu = xid & fc_cpu_mask;
+
+	if (cpu >= nr_cpu_ids || !cpu_possible(cpu)) {
+		printk_ratelimited(KERN_ERR
+			"libfc: lookup request for XID = %d, "

drivers/scsi/libfc/fc_exch.c static struct fc_exch *fc_exch_find(struct fc_exch_mgr *mp, u16 xid) · line 924

Quoted 10 lines
drivers/scsi/libfc/fc_exch.c +4 -1
+			"indicates invalid CPU %d\n", xid, cpu);
+		return NULL;
+	}
 
 	if ((xid >= mp->min_xid) && (xid <= mp->max_xid)) {
-		pool = per_cpu_ptr(mp->pool, xid & fc_cpu_mask);
+		pool = per_cpu_ptr(mp->pool, cpu);
 		spin_lock_bh(&pool->lock);
 		ep = fc_exch_ptr_get(pool, (xid - mp->min_xid) >> fc_cpu_order);
 		if (ep) {

@Martin, do you queue the libfc patches as well?

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
#5 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Johannes" == Johannes Thumshirn <[email protected]> writes:

Johannes> @Martin, do you queue the libfc patches as well?

Sure.

(Sorry about the delay, been on vacation).

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#6 lore raw
In reply to Chris Leech
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Chris" == Chris Leech <[email protected]> writes:

Chris> In the receive path libfc extracts a cpu number from the ox_id in Chris> the fiber channel header and uses that to do a per_cpu_ptr Chris> conversion. If, for some reason, a frame is received with an Chris> invalid ox_id, per_cpu_ptr will return an invalid pointer and the Chris> libfc receive path will panic the system trying to use it.

Applied to 4.8/scsi-queue.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering