]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
libfc: sanity check cpu number extracted from xid
authorChris Leech <cleech@redhat.com>
Thu, 30 Jun 2016 15:32:36 +0000 (08:32 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 14 Jul 2016 01:49:57 +0000 (21:49 -0400)
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.

Signed-off-by: Chris Leech <cleech@redhat.com>
Acked-by: Johannes Thumshirn <jth@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/libfc/fc_exch.c

index 30f9ef0c0d4f8cea52b182f370a04ed1ba4a9908..e72673b0a8fb4ba810097a4c57b8cc3d3b8d199f 100644 (file)
@@ -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) {