From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8055 invoked by alias); 29 Jun 2007 09:07:22 -0000 Received: (qmail 7959 invoked by uid 22791); 29 Jun 2007 09:07:22 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 29 Jun 2007 09:07:11 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l5T9982Z028933; Fri, 29 Jun 2007 11:09:08 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id l5T997wE028924; Fri, 29 Jun 2007 11:09:07 +0200 Date: Fri, 29 Jun 2007 09:07:00 -0000 From: Jakub Jelinek To: Ulrich Drepper , Roland McGrath Cc: Glibc hackers Subject: [PATCH] Find .note.ABI-tag notes even when multiple notes are in one PT_NOTE segment Message-ID: <20070629090907.GD4603@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2007-06/txt/msg00019.txt.bz2 Hi! All other places in glibc that handle notes already handle multiple notes in PT_NOTE segment (which ELF gABI allows), just .note.ABI-tag code in ld.so and ldconfig insisted it is the only note present. 2007-06-29 Jakub Jelinek * elf/dl-load.c (open_verify): Find .note.ABI-tag notes even in PT_NOTE segments with multiple notes. * elf/readelflib.c (process_elf_file): Likewise. --- libc/elf/dl-load.c.jj 2007-06-29 10:19:54.000000000 +0200 +++ libc/elf/dl-load.c 2007-06-29 10:45:28.000000000 +0200 @@ -1634,7 +1634,7 @@ open_verify (const char *name, struct fi { ElfW(Ehdr) *ehdr; ElfW(Phdr) *phdr, *ph; - ElfW(Word) *abi_note, abi_note_buf[8]; + ElfW(Word) *abi_note; unsigned int osversion; size_t maplength; @@ -1751,20 +1751,37 @@ open_verify (const char *name, struct fi /* Check .note.ABI-tag if present. */ for (ph = phdr; ph < &phdr[ehdr->e_phnum]; ++ph) - if (ph->p_type == PT_NOTE && ph->p_filesz == 32 && ph->p_align >= 4) + if (ph->p_type == PT_NOTE && ph->p_filesz >= 32 && ph->p_align >= 4) { - if (ph->p_offset + 32 <= (size_t) fbp->len) + ElfW(Addr) size = ph->p_filesz; + + if (ph->p_offset + size <= (size_t) fbp->len) abi_note = (void *) (fbp->buf + ph->p_offset); else { + abi_note = alloca (size); __lseek (fd, ph->p_offset, SEEK_SET); - if (__libc_read (fd, (void *) abi_note_buf, 32) != 32) + if (__libc_read (fd, (void *) abi_note, size) != size) goto read_error; + } - abi_note = abi_note_buf; + while (memcmp (abi_note, &expected_note, sizeof (expected_note))) + { +#define ROUND(len) (((len) + sizeof (ElfW(Word)) - 1) & -sizeof (ElfW(Word))) + ElfW(Addr) note_size = 3 * sizeof (ElfW(Word)) + + ROUND (abi_note[0]) + + ROUND (abi_note[1]); + + if (size - 32 < note_size) + { + size = 0; + break; + } + size -= note_size; + abi_note = (void *) abi_note + note_size; } - if (memcmp (abi_note, &expected_note, sizeof (expected_note))) + if (size == 0) continue; osversion = (abi_note[5] & 0xff) * 65536 --- libc/elf/readelflib.c.jj 2005-12-14 11:05:56.000000000 +0100 +++ libc/elf/readelflib.c 2007-06-29 10:46:00.000000000 +0200 @@ -1,4 +1,4 @@ -/* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1999, 2000, 2001, 2002, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Andreas Jaeger , 1999 and Jakub Jelinek , 1999. @@ -127,16 +127,37 @@ process_elf_file (const char *file_name, break; case PT_NOTE: - if (!*osversion && segment->p_filesz == 32 && segment->p_align >= 4) + if (!*osversion && segment->p_filesz >= 32 && segment->p_align >= 4) { ElfW(Word) *abi_note = (ElfW(Word) *) (file_contents + segment->p_offset); - if (abi_note [0] == 4 && abi_note [1] == 16 && abi_note [2] == 1 - && memcmp (abi_note + 3, "GNU", 4) == 0) - *osversion = (abi_note [4] << 24) | - ((abi_note [5] & 0xff) << 16) | - ((abi_note [6] & 0xff) << 8) | - (abi_note [7] & 0xff); + ElfW(Addr) size = segment->p_filesz; + + while (abi_note [0] != 4 || abi_note [1] != 16 + || abi_note [2] != 1 + || memcmp (abi_note + 3, "GNU", 4) != 0) + { +#define ROUND(len) (((len) + sizeof (ElfW(Word)) - 1) & -sizeof (ElfW(Word))) + ElfW(Addr) note_size = 3 * sizeof (ElfW(Word)) + + ROUND (abi_note[0]) + + ROUND (abi_note[1]); + + if (size - 32 < note_size || note_size == 0) + { + size = 0; + break; + } + size -= note_size; + abi_note = (void *) abi_note + note_size; + } + + if (size == 0) + break; + + *osversion = (abi_note [4] << 24) | + ((abi_note [5] & 0xff) << 16) | + ((abi_note [6] & 0xff) << 8) | + (abi_note [7] & 0xff); } break; Jakub