lkml.org 
[lkml]   [2021]   [Dec]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH] kprobes: fix out-of-bounds in register_kretprobe
    Date
    When the data 'rp->data_size' is negative, the code
    'sizeof(struct kretprobe_instance)+rp->data_size'
    is less than 'sizeof(struct kretprobe_instance)'

    At this time, the pointer 'inst' may be out of
    bound when it is in use.

    Signed-off-by: zhangyue <zhangyue1@kylinos.cn>
    ---
    kernel/kprobes.c | 5 +++--
    1 file changed, 3 insertions(+), 2 deletions(-)

    diff --git a/kernel/kprobes.c b/kernel/kprobes.c
    index 1cf8bca1ea86..71cf6bde299f 100644
    --- a/kernel/kprobes.c
    +++ b/kernel/kprobes.c
    @@ -1983,7 +1983,7 @@ int kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long o
    int register_kretprobe(struct kretprobe *rp)
    {
    int ret;
    - struct kretprobe_instance *inst;
    + struct kretprobe_instance *inst = NULL;
    int i;
    void *addr;

    @@ -2024,7 +2024,8 @@ int register_kretprobe(struct kretprobe *rp)

    rp->rph->rp = rp;
    for (i = 0; i < rp->maxactive; i++) {
    - inst = kzalloc(sizeof(struct kretprobe_instance) +
    + if (rp->data_size >= 0)
    + inst = kzalloc(sizeof(struct kretprobe_instance) +
    rp->data_size, GFP_KERNEL);
    if (inst == NULL) {
    refcount_set(&rp->rph->ref, i);
    --
    2.30.0
    \
     
     \ /
      Last update: 2021-12-01 06:51    [W:4.674 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site