Thread: Accesing a const char * const *

  1. #1
    Registered User
    Join Date
    Jul 2022
    Posts
    1

    Accesing a const char * const *

    Hi, I have beginning with eBPF filters in Linux and coding few PoCs, now I'm trying to hook sys_execve whose signature is:

    const char __user *filename, const char __user *const __user *__argv, const char __user *const __user *__envp)

    I have successfully hooked execve userland function whose signature is

    const char *path, char *const argv[], char *const envp[])

    with this code:

    Code:
    
    
    Code:
    #include <uapi/linux/ptrace.h> 
    
    
    int count(struct pt_regs *ctx) { 
             
             
            char * buf[50]; 
             
    
            bpf_probe_read(&buf, sizeof(buf), (void *)PT_REGS_PARM3(ctx)); 
             
             
    
            bpf_trace_printk("whatever env var: %s", *&buf[12]); 
       
    
        return 0; 
    };
    
    


    But when I try to hook sys_execve I can't access the cons char * const *

    This doesn't work

    Code:
    
    
    Code:
    #include <uapi/linux/ptrace.h> 
    
    
    int count(struct pt_regs *ctx) { 
       
    
      const char * const * buf[50]; 
      
      bpf_probe_read(&buf, sizeof(buf),(void *)PT_REGS_PARM3(ctx)); 
       
    
      bpf_trace_printk("whatever env var: %s", *&buf[0]); 
         
        return 0; 
    }
    
    
    




  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    These two do not match:
    Code:
        const char * const * buf[50];
        const char * const * x;
    The [50] is kind of like adding yet another *.
    Have you tried it with just
    Code:
        const char * const buf[50];
        // or even just
        const char * buf[50];
    It's also odd to say *&buf[0]. Why not just buf[0]?
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Different between int * const ptr ,const char *sPtr
    By ncode in forum C Programming
    Replies: 8
    Last Post: 01-13-2012, 08:52 AM
  2. Replies: 4
    Last Post: 04-20-2011, 01:19 PM
  3. Replies: 3
    Last Post: 11-15-2009, 04:57 AM
  4. Replies: 1
    Last Post: 04-03-2009, 08:52 AM
  5. Replies: 7
    Last Post: 04-28-2008, 09:20 AM

Tags for this Thread