Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Jun 2019 07:37:11 -0700
From:      Conrad Meyer <cem@freebsd.org>
To:        Mark Millard <marklmi@yahoo.com>
Cc:        FreeBSD Hackers <freebsd-hackers@freebsd.org>,  freeBSD PowerPC ML <freebsd-ppc@freebsd.org>
Subject:   Re: kern_execve using vm_page_zero_invalid but not vm_page_set_validclean to load /sbin/init ?
Message-ID:  <CAG6CVpV5FBHgOTgxEgRmP%2B46Vm7mxoPCPECDJiq3k=D4qZ8PCA@mail.gmail.com>
In-Reply-To: <1464D960-A1D6-404A-BB10-E615E2D14C1D@yahoo.com>
References:  <1464D960-A1D6-404A-BB10-E615E2D14C1D@yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi Mark,

On Sun, Jun 9, 2019 at 11:17 PM Mark Millard via freebsd-hackers
<freebsd-hackers@freebsd.org> wrote:
> ...
> vm_pager_get_pages uses vm_page_zero_invalid
> to "Zero out partially filled data".
>
> But vm_page_zero_invalid does not zero every "invalid"
> byte but works in terms of units of DEV_BSIZE :
> ...
> The comment indicates that areas of "sub-DEV_BSIZE"
> should have been handled previously by
> vm_page_set_validclean .

Or another VM routine, yes (e.g., vm_page_set_valid_range).  The valid
and dirty bitmasks in vm_page only have a single bit per DEV_BSIZE
region, so care must be taken when marking any sub-DEV_BSIZE region as
valid to zero out the rest of the DEV_BSIZE region.  This is part of
the VM page contract.  I'm not sure it's related to the BSS, though.

> So, if, say, char**environ ends up at the start of .sbss
> consistently, does environ always end up zeroed independently
> of FileSz for the PT_LOAD that spans them?

It is required to be zeroed, yes.  If not, there is a bug.  If FileSz
covers BSS, that's a bug in the linker.  Either the trailing bytes of
the corresponding page in the executable should be zero (wasteful; on
amd64 ".comment" is packed in there instead), or the linker/loader
must zero them at initialization.  I'm not familiar with the
particular details here, but if you are interested I would suggest
looking at __elfN(load_section) in sys/kern/imgact_elf.c.

> The following is not necessarily an example of problematical
> figures but is just for showing an example structure of what
> FileSiz covers vs. MemSiz for PT_LOAD's that involve .sbss
> and .bss :
> ...

Your 2nd LOAD phdr's FileSiz matches up exactly with Segment .sbss
Offset minus Segment .tdata Offset, i.e., none of the FileSiz
corresponds to the (s)bss regions.  (Good!  At least the static linker
part looks sane.)  That said, the boundary is not page-aligned and the
section alignment requirement is much lower than page_size, so the
beginning of bss will share a file page with some data.  Something
should zero it at image activation.

(Tangent: sbss/bss probably do not need to be RWE on PPC!  On amd64,
init has three LOAD segments rather than two: one for rodata (R), one
for .text, .init, etc (RX); and one for .data (RW).)

Best,
Conrad



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAG6CVpV5FBHgOTgxEgRmP%2B46Vm7mxoPCPECDJiq3k=D4qZ8PCA>