Page MenuHomeFreeBSD

Fix kldxref failing for modules with a short mc_cval
ClosedPublic

Authored by mhorne063_gmail.com on Jan 15 2018, 7:21 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Jan 3, 6:57 AM
Unknown Object (File)
Thu, Jan 2, 9:50 AM
Unknown Object (File)
Dec 6 2024, 5:52 PM
Unknown Object (File)
Nov 28 2024, 5:28 AM
Unknown Object (File)
Nov 28 2024, 5:08 AM
Unknown Object (File)
Nov 27 2024, 11:31 AM
Unknown Object (File)
Nov 23 2024, 10:39 AM
Unknown Object (File)
Nov 23 2024, 10:25 AM
Subscribers

Details

Summary

Attempting to retrieve an md_cval string from a kernel module with
kldxref would throw a offset error for modules created using lld, since
this value would be placed at the end of all allocated sections.

Add an ef_read_seg_string method to the ef interface, to allow reading
strings of varying size without attempting to read beyond the segment's
bounds.

Bugzilla

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

mhorne063_gmail.com edited the summary of this revision. (Show Details)
mhorne063_gmail.com edited the summary of this revision. (Show Details)

Upload diff correctly with tabs and full context

cem added inline comments.
usr.sbin/kldxref/ef.c
516 ↗(On Diff #37990)

why would ofs be -1? Other methods don't seem to check for this condition.

517 ↗(On Diff #37990)

Why lseek+read instead of ef_read or pread?

527 ↗(On Diff #37990)

inconsistent return style -- probably just remove parens

usr.sbin/kldxref/ef_obj.c
312 ↗(On Diff #37990)

same as above (s.a.)

316 ↗(On Diff #37990)

is this a tab?

usr.sbin/kldxref/ef.c
516 ↗(On Diff #37990)

ef_read uses (Elf_Off)-1 to mean "no seek", this keeps the same interface

527 ↗(On Diff #37990)

kldxref is already quite inconsistent; I count 47 return ( and 66 return [^(]. IMO it makes sense to follow style(9) when there's this much existing inconsistency.

usr.sbin/kldxref/ef.c
527 ↗(On Diff #37990)

That's an ok theory I can get behind, but this patch isn't internally consistent either. See the two returns directly above (0).

usr.sbin/kldxref/ef.c
527 ↗(On Diff #37990)

Fair enough, the patch should at least be self-consistent.

usr.sbin/kldxref/ef.c
517 ↗(On Diff #37990)

ef_read expects to read a certain length and returns an error if it comes up short, which is what we are working around here. On the other hand, pread seems slightly cleaner for this purpose so I will update it to use that.

usr.sbin/kldxref/ef.c
517 ↗(On Diff #37990)

Note that in the earlier patch we accepted (Elf_Off)-1 as "no seek", and that precluded using pread. But we don't need this for strings so Mitchell dropped it.

kib added inline comments.
usr.sbin/kldxref/ef.c
104 ↗(On Diff #38036)

I t is tempting to use the chance and switch to designated initializers.

506 ↗(On Diff #38036)

No initialization in declarations.

Wny u_long ?

518 ↗(On Diff #38036)

Why not return errno there ?

532 ↗(On Diff #38036)

Again, why not return (errno) ?

A lot of these comments address issues/inconsistencies already present in the source. I will create a subsequent cleanup patch to address these but follow what is there at the moment for this patch, since @emaste wants this merged to fix the lld build process.

This revision is now accepted and ready to land.Jan 16 2018, 5:59 PM
cem added inline comments.
usr.sbin/kldxref/ef.c
506 ↗(On Diff #38036)

Matches existing style of file -- ok for now, IMO.

This revision was automatically updated to reflect the committed changes.