Re: [PATCH drivers/misc 0/4] lkdtm: Various clean ups

From: Randy Dunlap
Date: Wed Jun 24 2020 - 21:46:16 EST


On 6/24/20 3:35 PM, Randy Dunlap wrote:
> On 6/24/20 3:23 PM, Randy Dunlap wrote:
>> On 6/24/20 3:01 PM, Richard Weinberger wrote:
>>> On Wed, Jun 24, 2020 at 11:29 PM Randy Dunlap <rdunlap@xxxxxxxxxxxxx> wrote:
>>>>
>>>> On 6/24/20 1:36 PM, Kees Cook wrote:
>>>>> On Wed, Jun 24, 2020 at 09:23:25AM +0200, Richard Weinberger wrote:
>>>>>> ----- UrsprÃngliche Mail -----
>>>>>>>>> Regardless, it seems arch/x86/um/asm/desc.h is not needed any more?
>>>>>>>
>>>>>>>> True that, we can rip the file.
>>>>>>>
>>>>>>> Has anyone fixed the uml build errors?
>>>>>>
>>>>>> I didn't realize that this is a super urgent issue. ;-)
>>>>>>
>>>>>> Kees, if you want you can carry a patch in your series, I'll ack it.
>>>>>> Otherwise I can also do a patch and bring it via the uml tree upstream
>>>>>> as soon more fixes queued up.
>>>>>
>>>>> I think the lkdtm change will tweak this bug, so I'm happy to carry the
>>>>> patch (I just haven't had time to create and test one). Is it really
>>>>> just as simple as removing arch/x86/um/asm/desc.h?
>>>>>
>>>>
>>>> I just tried that and the build is still failing, so No, it's not that simple.
>>>>
>>>> But thanks for offering.
>>>>
>>>> I'll just ignore the UML build errors for now.
>>>
>>> This is a allyesconfig?
>>> I just gave CONFIG_LKDTM=y a try, builds fine here.
>>>
>>
>> I'm building linux-next and it fails.
>
> More specifically, uml for i386 fails. x86_64 is OK.
> The problem is with the <asm/desc.h> file.
> I'm tampering with it...

I'm not getting anywhere with this. Too many mazes of tiny twisty passages.

>>> But the desc.h in uml is still in vain and can be deleted AFAICT.

Looks like lkdtm/bugs.c needs to get/use arch/x86/include/asm/processor.h
but it actually uses arch/x86/um/asm/processor*.h, which does not have the
needed structs etc.


Here are the build errors and warnings that I am seeing with allmodconfig:


CC [M] drivers/misc/lkdtm/bugs.o
In file included from ../arch/x86/include/asm/desc.h:11:0,
from ../drivers/misc/lkdtm/bugs.c:17:
../arch/x86/include/asm/cpu_entry_area.h:65:42: error: invalid application of âsizeofâ to incomplete type âstruct x86_hw_tssâ
unsigned long stack[(PAGE_SIZE - sizeof(struct x86_hw_tss)) / sizeof(unsigned long)];
^~~~~~
../arch/x86/include/asm/cpu_entry_area.h:66:20: error: field âtssâ has incomplete type
struct x86_hw_tss tss;
^~~
../arch/x86/include/asm/cpu_entry_area.h:89:26: error: field âentry_stack_pageâ has incomplete type
struct entry_stack_page entry_stack_page;
^~~~~~~~~~~~~~~~
../arch/x86/include/asm/cpu_entry_area.h:100:20: error: field âtssâ has incomplete type
struct tss_struct tss;
^~~
In file included from ../drivers/misc/lkdtm/bugs.c:17:0:
../arch/x86/include/asm/desc.h:45:25: error: âGDT_ENTRIESâ undeclared here (not in a function); did you mean âLDT_ENTRIESâ?
struct desc_struct gdt[GDT_ENTRIES];
^~~~~~~~~~~
LDT_ENTRIES
../arch/x86/include/asm/desc.h: In function â__set_tss_descâ:
../arch/x86/include/asm/desc.h:186:10: error: â__KERNEL_TSS_LIMITâ undeclared (first use in this function); did you mean â__KERNEL__â?
__KERNEL_TSS_LIMIT);
^~~~~~~~~~~~~~~~~~
__KERNEL__
../arch/x86/include/asm/desc.h:186:10: note: each undeclared identifier is reported only once for each function it appears in
../arch/x86/include/asm/desc.h: In function ânative_set_ldtâ:
../arch/x86/include/asm/desc.h:202:40: error: âGDT_ENTRY_LDTâ undeclared (first use in this function); did you mean âGDT_ENTRY_INITâ?
write_gdt_entry(get_cpu_gdt_rw(cpu), GDT_ENTRY_LDT,
^
../arch/x86/include/asm/desc.h:123:75: note: in definition of macro âwrite_gdt_entryâ
#define write_gdt_entry(dt, entry, desc, type) native_write_gdt_entry(dt, entry, desc, type)
^~~~~
../arch/x86/include/asm/desc.h: In function ânative_load_tr_descâ:
../arch/x86/include/asm/desc.h:259:31: error: âGDT_ENTRY_TSSâ undeclared (first use in this function); did you mean âGDT_ENTRIESâ?
asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
^~~~~~~~~~~~~
GDT_ENTRIES
../arch/x86/include/asm/desc.h: In function ânative_load_tlsâ:
../arch/x86/include/asm/desc.h:278:33: error: âstruct thread_structâ has no member named âtls_arrayâ
gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
^~
In file included from ../arch/x86/include/asm/string.h:3:0,
from ../include/linux/string.h:20,
from ../arch/x86/um/asm/processor_32.h:9,
from ../arch/x86/um/asm/processor.h:10,
from ../include/linux/rcupdate.h:30,
from ../include/linux/rculist.h:11,
from ../include/linux/pid.h:5,
from ../include/linux/sched.h:14,
from ../drivers/misc/lkdtm/bugs.c:10:
../arch/x86/include/asm/desc.h: In function âforce_reload_TRâ:
../arch/x86/include/asm/desc.h:288:18: error: âGDT_ENTRY_TSSâ undeclared (first use in this function); did you mean âGDT_ENTRIESâ?
memcpy(&tss, &d[GDT_ENTRY_TSS], sizeof(tss_desc));
^
../arch/x86/include/asm/string_32.h:182:45: note: in definition of macro âmemcpyâ
#define memcpy(t, f, n) __builtin_memcpy(t, f, n)
^
In file included from ../include/linux/kernel.h:11:0,
from ../drivers/misc/lkdtm/lkdtm.h:7,
from ../drivers/misc/lkdtm/bugs.c:8:
../arch/x86/include/asm/desc.h: In function âinvalidate_tss_limitâ:
../arch/x86/include/asm/desc.h:327:32: error: âTIF_IO_BITMAPâ undeclared (first use in this function); did you mean âCONFIG_SBITMAPâ?
if (unlikely(test_thread_flag(TIF_IO_BITMAP)))
^
../include/linux/compiler.h:78:42: note: in definition of macro âunlikelyâ
# define unlikely(x) __builtin_expect(!!(x), 0)
^
../arch/x86/include/asm/desc.h:327:15: note: in expansion of macro âtest_thread_flagâ
if (unlikely(test_thread_flag(TIF_IO_BITMAP)))
^~~~~~~~~~~~~~~~
In file included from ../drivers/misc/lkdtm/bugs.c:17:0:
../arch/x86/include/asm/desc.h: At top level:
../arch/x86/include/asm/desc.h:334:0: warning: "LDT_empty" redefined
#define LDT_empty(info) \

In file included from ../arch/um/include/asm/mmu.h:10:0,
from ../include/linux/mm_types.h:18,
from ../include/linux/sched/signal.h:13,
from ../drivers/misc/lkdtm/bugs.c:11:
../arch/x86/um/asm/mm_context.h:65:0: note: this is the location of the previous definition
#define LDT_empty(info) (_LDT_empty(info))

In file included from ../drivers/misc/lkdtm/bugs.c:17:0:
../arch/x86/include/asm/desc.h: In function âget_cpu_gdt_rwâ:
../arch/x86/include/asm/desc.h:54:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^


--
~Randy
Reported-by: Randy Dunlap <rdunlap@xxxxxxxxxxxxx>