public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Aurelien Jarno <aurel32@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc] localedef: check magic value on archive load [BZ #28650]
Date: Tue,  7 Dec 2021 22:33:07 +0000 (GMT)	[thread overview]
Message-ID: <20211207223307.6A0623858C2C@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=cbab7f726877badc5059316e7248be7c3bff9d96

commit cbab7f726877badc5059316e7248be7c3bff9d96
Author: Aurelien Jarno <aurelien@aurel32.net>
Date:   Sun Dec 5 11:51:17 2021 +0100

    localedef: check magic value on archive load [BZ #28650]
    
    localedef currently blindly trust the archive header. When passed an
    archive file with the wrong endianess, this leads to a segmentation
    fault:
    
      $ localedef --big-endian --list-archive /usr/lib/locale/locale-archive
      Segmentation fault (core dumped)
    
    When passed non-archive files, asserts are reported on the best case,
    but sometimes it can lead to a segmentation fault:
    
      $ localedef --list-archive /bin/true
      localedef: programs/locarchive.c:1643: show_archive_content: Assertion `used < GET (head->namehash_used)' failed.
      Aborted (core dumped)
    
      $ localedef --list-archive /usr/lib/locale/C.utf8/LC_COLLATE
      Segmentation fault (core dumped)
    
    This patch improves the user experience by looking at the magic value,
    which is always written, but never checked. It should still be possible
    to trigger a segmentation fault with crafted files, but this already
    catch many cases.

Diff:
---
 locale/programs/locarchive.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c
index eeec3ab648..477499bd40 100644
--- a/locale/programs/locarchive.c
+++ b/locale/programs/locarchive.c
@@ -654,6 +654,13 @@ open_archive (struct locarhandle *ah, bool readonly)
       error (EXIT_FAILURE, errno, _("cannot read archive header"));
     }
 
+  /* Check the magic value */
+  if (GET (head.magic) != AR_MAGIC)
+    {
+      (void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead));
+      error (EXIT_FAILURE, 0, _("bad magic value in archive header"));
+    }
+
   ah->fd = fd;
   ah->mmaped = st.st_size;


                 reply	other threads:[~2021-12-07 22:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211207223307.6A0623858C2C@sourceware.org \
    --to=aurel32@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).