aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/bpf')
-rw-r--r--kernel/bpf/core.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index d315b393abdd..ba03ec39efb3 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1572,13 +1572,32 @@ int bpf_prog_array_length(struct bpf_prog_array __rcu *progs)
1572 return cnt; 1572 return cnt;
1573} 1573}
1574 1574
1575static bool bpf_prog_array_copy_core(struct bpf_prog **prog,
1576 u32 *prog_ids,
1577 u32 request_cnt)
1578{
1579 int i = 0;
1580
1581 for (; *prog; prog++) {
1582 if (*prog == &dummy_bpf_prog.prog)
1583 continue;
1584 prog_ids[i] = (*prog)->aux->id;
1585 if (++i == request_cnt) {
1586 prog++;
1587 break;
1588 }
1589 }
1590
1591 return !!(*prog);
1592}
1593
1575int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs, 1594int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs,
1576 __u32 __user *prog_ids, u32 cnt) 1595 __u32 __user *prog_ids, u32 cnt)
1577{ 1596{
1578 struct bpf_prog **prog; 1597 struct bpf_prog **prog;
1579 unsigned long err = 0; 1598 unsigned long err = 0;
1580 u32 i = 0, *ids;
1581 bool nospc; 1599 bool nospc;
1600 u32 *ids;
1582 1601
1583 /* users of this function are doing: 1602 /* users of this function are doing:
1584 * cnt = bpf_prog_array_length(); 1603 * cnt = bpf_prog_array_length();
@@ -1595,16 +1614,7 @@ int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs,
1595 return -ENOMEM; 1614 return -ENOMEM;
1596 rcu_read_lock(); 1615 rcu_read_lock();
1597 prog = rcu_dereference(progs)->progs; 1616 prog = rcu_dereference(progs)->progs;
1598 for (; *prog; prog++) { 1617 nospc = bpf_prog_array_copy_core(prog, ids, cnt);
1599 if (*prog == &dummy_bpf_prog.prog)
1600 continue;
1601 ids[i] = (*prog)->aux->id;
1602 if (++i == cnt) {
1603 prog++;
1604 break;
1605 }
1606 }
1607 nospc = !!(*prog);
1608 rcu_read_unlock(); 1618 rcu_read_unlock();
1609 err = copy_to_user(prog_ids, ids, cnt * sizeof(u32)); 1619 err = copy_to_user(prog_ids, ids, cnt * sizeof(u32));
1610 kfree(ids); 1620 kfree(ids);
@@ -1683,22 +1693,25 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array,
1683} 1693}
1684 1694
1685int bpf_prog_array_copy_info(struct bpf_prog_array __rcu *array, 1695int bpf_prog_array_copy_info(struct bpf_prog_array __rcu *array,
1686 __u32 __user *prog_ids, u32 request_cnt, 1696 u32 *prog_ids, u32 request_cnt,
1687 __u32 __user *prog_cnt) 1697 u32 *prog_cnt)
1688{ 1698{
1699 struct bpf_prog **prog;
1689 u32 cnt = 0; 1700 u32 cnt = 0;
1690 1701
1691 if (array) 1702 if (array)
1692 cnt = bpf_prog_array_length(array); 1703 cnt = bpf_prog_array_length(array);
1693 1704
1694 if (copy_to_user(prog_cnt, &cnt, sizeof(cnt))) 1705 *prog_cnt = cnt;
1695 return -EFAULT;
1696 1706
1697 /* return early if user requested only program count or nothing to copy */ 1707 /* return early if user requested only program count or nothing to copy */
1698 if (!request_cnt || !cnt) 1708 if (!request_cnt || !cnt)
1699 return 0; 1709 return 0;
1700 1710
1701 return bpf_prog_array_copy_to_user(array, prog_ids, request_cnt); 1711 /* this function is called under trace/bpf_trace.c: bpf_event_mutex */
1712 prog = rcu_dereference_check(array, 1)->progs;
1713 return bpf_prog_array_copy_core(prog, prog_ids, request_cnt) ? -ENOSPC
1714 : 0;
1702} 1715}
1703 1716
1704static void bpf_prog_free_deferred(struct work_struct *work) 1717static void bpf_prog_free_deferred(struct work_struct *work)