Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
fork

Configure Feed

Select the types of activity you want to include in your feed.

RDMA/efa: Handle mmap insertions overflow

When inserting a new mmap entry to the xarray we should check for
'mmap_page' overflow as it is limited to 32 bits.

Fixes: 40909f664d27 ("RDMA/efa: Add EFA verbs implementation")
Signed-off-by: Gal Pressman <galpress@amazon.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>

authored by

Gal Pressman and committed by
Doug Ledford
7a5834e4 52925434

+16 -5
+16 -5
drivers/infiniband/hw/efa/efa_verbs.c
··· 204 204 void *obj, u64 address, u64 length, u8 mmap_flag) 205 205 { 206 206 struct efa_mmap_entry *entry; 207 + u32 next_mmap_page; 207 208 int err; 208 209 209 210 entry = kmalloc(sizeof(*entry), GFP_KERNEL); ··· 217 216 entry->mmap_flag = mmap_flag; 218 217 219 218 xa_lock(&ucontext->mmap_xa); 219 + if (check_add_overflow(ucontext->mmap_xa_page, 220 + (u32)(length >> PAGE_SHIFT), 221 + &next_mmap_page)) 222 + goto err_unlock; 223 + 220 224 entry->mmap_page = ucontext->mmap_xa_page; 221 - ucontext->mmap_xa_page += DIV_ROUND_UP(length, PAGE_SIZE); 225 + ucontext->mmap_xa_page = next_mmap_page; 222 226 err = __xa_insert(&ucontext->mmap_xa, entry->mmap_page, entry, 223 227 GFP_KERNEL); 228 + if (err) 229 + goto err_unlock; 230 + 224 231 xa_unlock(&ucontext->mmap_xa); 225 - if (err){ 226 - kfree(entry); 227 - return EFA_MMAP_INVALID; 228 - } 229 232 230 233 ibdev_dbg( 231 234 &dev->ibdev, ··· 237 232 entry->obj, entry->address, entry->length, get_mmap_key(entry)); 238 233 239 234 return get_mmap_key(entry); 235 + 236 + err_unlock: 237 + xa_unlock(&ucontext->mmap_xa); 238 + kfree(entry); 239 + return EFA_MMAP_INVALID; 240 + 240 241 } 241 242 242 243 int efa_query_device(struct ib_device *ibdev,