@@ -59,7 +59,7 @@ static void llext_init_mem_part(struct llext *ext, enum llext_mem mem_idx,
5959}
6060
6161static int llext_copy_section (struct llext_loader * ldr , struct llext * ext ,
62- enum llext_mem mem_idx )
62+ enum llext_mem mem_idx , const struct llext_load_param * ldr_parm )
6363{
6464 int ret ;
6565
@@ -68,18 +68,31 @@ static int llext_copy_section(struct llext_loader *ldr, struct llext *ext,
6868 }
6969 ext -> mem_size [mem_idx ] = ldr -> sects [mem_idx ].sh_size ;
7070
71- if (ldr -> sects [mem_idx ].sh_type != SHT_NOBITS &&
72- IS_ENABLED (CONFIG_LLEXT_STORAGE_WRITABLE )) {
73- /* Directly use data from the ELF buffer if peek() is supported */
74- ext -> mem [mem_idx ] = llext_peek (ldr , ldr -> sects [mem_idx ].sh_offset );
75- if (ext -> mem [mem_idx ]) {
76- llext_init_mem_part (ext , mem_idx , (uintptr_t )ext -> mem [mem_idx ],
77- ldr -> sects [mem_idx ].sh_size );
71+ if (IS_ENABLED (CONFIG_LLEXT_STORAGE_WRITABLE )) {
72+ if (ldr -> sects [mem_idx ].sh_type != SHT_NOBITS ) {
73+ /* Directly use data from the ELF buffer if peek() is supported */
74+ ext -> mem [mem_idx ] = llext_peek (ldr , ldr -> sects [mem_idx ].sh_offset );
75+ if (ext -> mem [mem_idx ]) {
76+ llext_init_mem_part (ext , mem_idx , (uintptr_t )ext -> mem [mem_idx ],
77+ ldr -> sects [mem_idx ].sh_size );
78+ ext -> mem_on_heap [mem_idx ] = false;
79+ return 0 ;
80+ }
81+ } else if (ldr_parm && ldr_parm -> pre_located ) {
82+ /*
83+ * ldr_parm cannot be NULL here with the current flow, but
84+ * we add a check to make it future-proof
85+ */
86+ ext -> mem [mem_idx ] = NULL ;
7887 ext -> mem_on_heap [mem_idx ] = false;
7988 return 0 ;
8089 }
8190 }
8291
92+ if (ldr_parm && ldr_parm -> pre_located ) {
93+ return - EFAULT ;
94+ }
95+
8396 /* On ARM with an MPU a pow(2, N)*32 sized and aligned region is needed,
8497 * otherwise its typically an mmu page (sized and aligned memory region)
8598 * we are after that we can assign memory permission bits on.
@@ -132,24 +145,25 @@ static int llext_copy_section(struct llext_loader *ldr, struct llext *ext,
132145
133146int llext_copy_strings (struct llext_loader * ldr , struct llext * ext )
134147{
135- int ret = llext_copy_section (ldr , ext , LLEXT_MEM_SHSTRTAB );
148+ int ret = llext_copy_section (ldr , ext , LLEXT_MEM_SHSTRTAB , NULL );
136149
137150 if (!ret ) {
138- ret = llext_copy_section (ldr , ext , LLEXT_MEM_STRTAB );
151+ ret = llext_copy_section (ldr , ext , LLEXT_MEM_STRTAB , NULL );
139152 }
140153
141154 return ret ;
142155}
143156
144- int llext_copy_regions (struct llext_loader * ldr , struct llext * ext )
157+ int llext_copy_regions (struct llext_loader * ldr , struct llext * ext ,
158+ const struct llext_load_param * ldr_parm )
145159{
146160 for (enum llext_mem mem_idx = 0 ; mem_idx < LLEXT_MEM_COUNT ; mem_idx ++ ) {
147161 /* strings have already been copied */
148162 if (ext -> mem [mem_idx ]) {
149163 continue ;
150164 }
151165
152- int ret = llext_copy_section (ldr , ext , mem_idx );
166+ int ret = llext_copy_section (ldr , ext , mem_idx , ldr_parm );
153167
154168 if (ret < 0 ) {
155169 return ret ;
0 commit comments