Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Oct 2018 15:17:57 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 232289] kern/link_elf.c fails for small sections sizes (<sizeof(void *))  (also affects pcpu and vnet)
Message-ID:  <bug-232289-227@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D232289

            Bug ID: 232289
           Summary: kern/link_elf.c fails for small sections sizes
                    (<sizeof(void *))  (also affects pcpu and vnet)
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: bz@FreeBSD.org

Hi,

debugging PR230857 I noticed a small problem (here's output from instrument=
ed
kernel) loading a module with a single char variable in a vnet_set and the =
. =3D
. + 1 workaround currently in place (hence 2 bytes section size).  The prob=
lem
here is count =3D=3D 0:

XXX-BZ link_elf_lookup_set: count 0 stop 0x1d400000 start 0x1d400000  <<=3D=
=3D pcpu
(unused)
XXX-BZ link_elf_lookup_set: count 0 stop 0x1d401272 start 0x1d401270  <<=3D=
=3D vnet
XXX-BZ parse_vnet: count 0 start 0x1d401270 stop 0x1d401272
XXX-BZ parse_vnet:682 error =3D 0
XXX-BZ link_elf_reloc_local:1619 /boot/kernel/z1.ko addr 0x1d400000 rel 0
relsize 0 rela 0 relasize 0

>From elfdump -a /boot/kernel/z1.ko:

entry: 6
        sh_name: set_vnet
        sh_type: SHT_PROGBITS
        sh_flags: SHF_WRITE|SHF_ALLOC
        sh_addr: 0x1270
        sh_offset: 624
        sh_size: 2
        sh_link: 0
        sh_info: 0
        sh_addralign: 1
        sh_entsize: 0

entry: 1
        st_name: __stop_set_vnet
        st_value: 0x1272
        st_size: 0
        st_info: STT_NOTYPE STB_GLOBAL
        st_shndx: 65521

entry: 3
        st_name: ___set_vnet_pad
        st_value: 0x1
        st_size: 0
        st_info: STT_NOTYPE STB_GLOBAL
        st_shndx: 65521

entry: 9
        st_name: __start_set_vnet
        st_value: 0x1270
        st_size: 0
        st_info: STT_NOTYPE STB_GLOBAL
        st_shndx: 65521

entry: 1
        st_name: vnet_entry_achar
        st_value: 0x1270
        st_size: 1
        st_info: STT_OBJECT STB_LOCAL
        st_shndx: 6



sys/kern/link_elf.c:

link_elf_lookup_set() does read the start and stop symbols:

        void **start, **stop;
        int len, error =3D 0, count;

..
        /* and the number of entries */
        count =3D stop - start;
        printf("XXX-BZ %s: count %d stop %#jx start %#jx\n", __func__, coun=
t,
(uintmax_t)(uintptr_t)stop, (uintmax_t)(uintptr_t)start);


The problem is that the addresses are stored in void ** and so 2 - 0 ! =3D =
2 but
0.

Hence, with the count being 0, so when parse_dpcpu() and parse_vnet() do a
count *=3D sizeof(void *);  0 * x will stay 0.

So the extra memory allocated in the set handlers will be roundup2(size,
sizeof(void *)) or 0.

Also the copy functions later will copy 0 bytes.

While there is no error, neither the memory needed is allocated, nor the da=
ta
needed is copied into the memory area.

With the start/stop symbols stored properly, future relocations would work,=
 the
memory accessed be bogus however.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-232289-227>