]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - fs/binfmt_flat.c
net/mlx5: Fix some error handling paths in 'mlx5e_tc_add_fdb_flow()'
[mirror_ubuntu-jammy-kernel.git] / fs / binfmt_flat.c
index 5d776f80ee50c22ae3eafe48bfaac144c6dae9cf..7ca3e0db06ffa456a78b06fc8913067a01bb9fa2 100644 (file)
@@ -433,6 +433,30 @@ static void old_reloc(unsigned long rl)
 
 /****************************************************************************/
 
+static inline u32 __user *skip_got_header(u32 __user *rp)
+{
+       if (IS_ENABLED(CONFIG_RISCV)) {
+               /*
+                * RISC-V has a 16 byte GOT PLT header for elf64-riscv
+                * and 8 byte GOT PLT header for elf32-riscv.
+                * Skip the whole GOT PLT header, since it is reserved
+                * for the dynamic linker (ld.so).
+                */
+               u32 rp_val0, rp_val1;
+
+               if (get_user(rp_val0, rp))
+                       return rp;
+               if (get_user(rp_val1, rp + 1))
+                       return rp;
+
+               if (rp_val0 == 0xffffffff && rp_val1 == 0xffffffff)
+                       rp += 4;
+               else if (rp_val0 == 0xffffffff)
+                       rp += 2;
+       }
+       return rp;
+}
+
 static int load_flat_file(struct linux_binprm *bprm,
                struct lib_info *libinfo, int id, unsigned long *extra_stack)
 {
@@ -782,7 +806,8 @@ static int load_flat_file(struct linux_binprm *bprm,
         * image.
         */
        if (flags & FLAT_FLAG_GOTPIC) {
-               for (rp = (u32 __user *)datapos; ; rp++) {
+               rp = skip_got_header((u32 __user *) datapos);
+               for (; ; rp++) {
                        u32 addr, rp_val;
                        if (get_user(rp_val, rp))
                                return -EFAULT;