From owner-svn-src-all@freebsd.org Fri Nov 23 23:29:15 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0FC94113453B; Fri, 23 Nov 2018 23:29:15 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AA5E5798A3; Fri, 23 Nov 2018 23:29:14 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 865E325633; Fri, 23 Nov 2018 23:29:14 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wANNTE16042908; Fri, 23 Nov 2018 23:29:14 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wANNTEAx042907; Fri, 23 Nov 2018 23:29:14 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201811232329.wANNTEAx042907@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 23 Nov 2018 23:29:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r340863 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 340863 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: AA5E5798A3 X-Spamd-Result: default: False [1.66 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_SPAM_LONG(0.42)[0.420,0]; NEURAL_SPAM_SHORT(0.51)[0.506,0]; NEURAL_SPAM_MEDIUM(0.73)[0.730,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Nov 2018 23:29:15 -0000 Author: kib Date: Fri Nov 23 23:29:14 2018 New Revision: 340863 URL: https://svnweb.freebsd.org/changeset/base/340863 Log: Generalize ELF parse_notes(). Remove the knowledge of the ABI note type and brandnote from it, instead provide it with a callback to do note-specific matching and data fetching. Implement callback to match against ELF brand. Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Modified: head/sys/kern/imgact_elf.c Modified: head/sys/kern/imgact_elf.c ============================================================================== --- head/sys/kern/imgact_elf.c Fri Nov 23 23:16:01 2018 (r340862) +++ head/sys/kern/imgact_elf.c Fri Nov 23 23:29:14 2018 (r340863) @@ -2341,8 +2341,9 @@ __elfN(note_procstat_auxv)(void *arg, struct sbuf *sb, } static boolean_t -__elfN(parse_notes)(struct image_params *imgp, Elf_Brandnote *checknote, - int32_t *osrel, const Elf_Phdr *pnote) +__elfN(parse_notes)(struct image_params *imgp, Elf_Note *checknote, + const char *note_vendor, const Elf_Phdr *pnote, + boolean_t (*cb)(const Elf_Note *, void *, boolean_t *), void *cb_arg) { const Elf_Note *note, *note0, *note_end; const char *note_name; @@ -2380,27 +2381,18 @@ __elfN(parse_notes)(struct image_params *imgp, Elf_Bra (const char *)note < sizeof(Elf_Note)) { goto retf; } - if (note->n_namesz != checknote->hdr.n_namesz || - note->n_descsz != checknote->hdr.n_descsz || - note->n_type != checknote->hdr.n_type) + if (note->n_namesz != checknote->n_namesz || + note->n_descsz != checknote->n_descsz || + note->n_type != checknote->n_type) goto nextnote; note_name = (const char *)(note + 1); - if (note_name + checknote->hdr.n_namesz >= - (const char *)note_end || strncmp(checknote->vendor, - note_name, checknote->hdr.n_namesz) != 0) + if (note_name + checknote->n_namesz >= + (const char *)note_end || strncmp(note_vendor, + note_name, checknote->n_namesz) != 0) goto nextnote; - /* - * Fetch the osreldate for binary - * from the ELF OSABI-note if necessary. - */ - if ((checknote->flags & BN_TRANSLATE_OSREL) != 0 && - checknote->trans_osrel != NULL) { - res = checknote->trans_osrel(note, osrel); + if (cb(note, cb_arg, &res)) goto ret; - } - res = TRUE; - goto ret; nextnote: note = (const Elf_Note *)((const char *)(note + 1) + roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE) + @@ -2413,26 +2405,54 @@ ret: return (res); } +struct brandnote_cb_arg { + Elf_Brandnote *brandnote; + int32_t *osrel; +}; + +static boolean_t +brandnote_cb(const Elf_Note *note, void *arg0, boolean_t *res) +{ + struct brandnote_cb_arg *arg; + + arg = arg0; + + /* + * Fetch the osreldate for binary from the ELF OSABI-note if + * necessary. + */ + *res = (arg->brandnote->flags & BN_TRANSLATE_OSREL) != 0 && + arg->brandnote->trans_osrel != NULL ? + arg->brandnote->trans_osrel(note, arg->osrel) : TRUE; + + return (TRUE); +} + /* * Try to find the appropriate ABI-note section for checknote, * fetch the osreldate for binary from the ELF OSABI-note. Only the * first page of the image is searched, the same as for headers. */ static boolean_t -__elfN(check_note)(struct image_params *imgp, Elf_Brandnote *checknote, +__elfN(check_note)(struct image_params *imgp, Elf_Brandnote *brandnote, int32_t *osrel) { const Elf_Phdr *phdr; const Elf_Ehdr *hdr; + struct brandnote_cb_arg b_arg; int i; hdr = (const Elf_Ehdr *)imgp->image_header; phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff); + b_arg.brandnote = brandnote; + b_arg.osrel = osrel; for (i = 0; i < hdr->e_phnum; i++) { - if (phdr[i].p_type == PT_NOTE && - __elfN(parse_notes)(imgp, checknote, osrel, &phdr[i])) + if (phdr[i].p_type == PT_NOTE && __elfN(parse_notes)(imgp, + &brandnote->hdr, brandnote->vendor, &phdr[i], brandnote_cb, + &b_arg)) { return (TRUE); + } } return (FALSE);