From patchwork Tue Sep 18 03:57:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 970915 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=jms.id.au Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="J/A8xwnT"; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Dq365jH0z9sCD for ; Tue, 18 Sep 2018 13:58:09 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 157AA8780A; Tue, 18 Sep 2018 03:58:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id elaHMsiE1Pnq; Tue, 18 Sep 2018 03:58:04 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 65B3B877F6; Tue, 18 Sep 2018 03:58:04 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 5CC031C2E16 for ; Tue, 18 Sep 2018 03:58:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 557A1877F7 for ; Tue, 18 Sep 2018 03:58:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DMMLhuew+1vX for ; Tue, 18 Sep 2018 03:58:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by whitealder.osuosl.org (Postfix) with ESMTPS id 5393C877EB for ; Tue, 18 Sep 2018 03:58:02 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id d4-v6so331443pfn.0 for ; Mon, 17 Sep 2018 20:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=Ouwvd0y8jC2CEVc6Uqgyg3V9PNtxhzMtjaPOvvAuTlA=; b=J/A8xwnTYeTk5ZEEzJb1FowHT1b5v6P3HRPJ0a0lHt60dLnCgnZ3KWR8wUCC/mYxHq Jn4uyWOenCAHG+fBizKKlX/Mz6Lp9NDRRIFjWjv98BwF20ql8rDgbc4aIyEOhmoQdm8G XxNnTZU2qX8mF9FuePACN5EdKk/DpD8Wy+myP5dVTnDDmY4x6+aSCXjEuvKQjKBy76+o rwwbVBlBgDYUXsO4jMej7zQneqjHtQi/GTK91A8Gao0abhgFfeJ6fOqFix7HuzFwucOS wqa2ARTXCPUe22UhRyyIulAi20ng1EWmRuXMxzHbli6ODcbLVT/wqaNRJ2xSf5hl061d HORA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=Ouwvd0y8jC2CEVc6Uqgyg3V9PNtxhzMtjaPOvvAuTlA=; b=UGXFYlRYJlgmCOBxNkkqyyhT9Ggc8opbDHkbkXTxKLFmjDTudlWfnGGsEbxpYxARTL aBSqWuKptlDQc+hE93YA4gSHW0YRADM0/Ezz4XwJzD1t9sE3v8adqaDtavTg09BIKvY8 lmBzZ3AIC1YjukEu3qY0WYQ6bLNpmVyXjUv7q6yeyz6SofQ+sU2Io7sgH3v9LLaVt0IU WY3ELJ2OH7/wE+nMrtvG0xsKnVCkoRYgH0vSfkQivYD5VYVS/qsqWdjYgNFR43rmWm+3 lqN8PnD4R+wKuzVDYZ/vlmsgnAYOuQu7zHDgL4RG7/Nkp35G5tawAUw95lEndRcHXhT4 DxKg== X-Gm-Message-State: APzg51Dr7I5/iWKmRJ8rqgMBMS/WQqRBQEKkXRp3YyENzmqPKfCeXTeD j//QTUT6o00ZlIuSsuoBELpMaCt0 X-Google-Smtp-Source: ANB0VdYDoCZflhZyddRNDIn672e+4h8zeNE7UT4QaaFHMvpZPhDRqKT4OvBBEDBppK7H62peZLQ+rw== X-Received: by 2002:a62:b0e:: with SMTP id t14-v6mr28352617pfi.36.1537243081424; Mon, 17 Sep 2018 20:58:01 -0700 (PDT) Received: from aurora.jms.id.au ([45.124.203.19]) by smtp.gmail.com with ESMTPSA id a192-v6sm28078141pfa.124.2018.09.17.20.57.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 17 Sep 2018 20:58:00 -0700 (PDT) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Tue, 18 Sep 2018 13:27:54 +0930 From: Joel Stanley To: buildroot@buildroot.org Date: Tue, 18 Sep 2018 13:27:50 +0930 Message-Id: <20180918035750.17651-1-joel@jms.id.au> X-Mailer: git-send-email 2.17.1 Subject: [Buildroot] [PATCH] dtc: Fix segfault reading powernv device tree X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.24 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Yann E . MORIN" MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" When running this command on a powernv machine, dtc crashes: dtc -f -I fs -O dts /sys/firmware/devicetree Upstream has fixed the segfault but have not made a release yet so we add the patch for now. Signed-off-by: Joel Stanley --- ...001-Kill-bogus-TYPE_BLOB-marker-type.patch | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 package/dtc/0001-Kill-bogus-TYPE_BLOB-marker-type.patch diff --git a/package/dtc/0001-Kill-bogus-TYPE_BLOB-marker-type.patch b/package/dtc/0001-Kill-bogus-TYPE_BLOB-marker-type.patch new file mode 100644 index 000000000000..d9c660ef51ad --- /dev/null +++ b/package/dtc/0001-Kill-bogus-TYPE_BLOB-marker-type.patch @@ -0,0 +1,138 @@ +From 9619c8619c37b9aea98100bcc15c51a5642e877e Mon Sep 17 00:00:00 2001 +From: Greg Kurz +Date: Thu, 30 Aug 2018 12:01:59 +0200 +Subject: [PATCH] Kill bogus TYPE_BLOB marker type + +Since commit 32b9c6130762 "Preserve datatype markers when emitting dts +format", we no longer try to guess the value type. Instead, we reuse +the type of the datatype markers when they are present, if the type +is either TYPE_UINT* or TYPE_STRING. + +This causes 'dtc -I fs' to crash: + +Starting program: /root/dtc -q -f -O dts -I fs /proc/device-tree +/dts-v1/; + +/ { + +Program received signal SIGSEGV, Segmentation fault. +__strlen_power8 () at ../sysdeps/powerpc/powerpc64/power8/strlen.S:47 +47 ld r12,0(r4) /* Load doubleword from memory. */ +(gdb) bt +#0 __strlen_power8 () at ../sysdeps/powerpc/powerpc64/power8/strlen.S:47 +#1 0x00007ffff7de3d10 in __GI__IO_fputs (str=, + fp=) at iofputs.c:33 +#2 0x000000001000c7a0 in write_propval (prop=0x100525e0, + f=0x7ffff7f718a0 <_IO_2_1_stdout_>) at treesource.c:245 + +The offending line is: + + fprintf(f, "%s", delim_start[emit_type]); + +where emit_type is TYPE_BLOB and: + +static const char *delim_start[] = { + [TYPE_UINT8] = "[", + [TYPE_UINT16] = "/bits/ 16 <", + [TYPE_UINT32] = "<", + [TYPE_UINT64] = "/bits/ 64 <", + [TYPE_STRING] = "", +}; + +/* Data blobs */ +enum markertype { + TYPE_NONE, + REF_PHANDLE, + REF_PATH, + LABEL, + TYPE_UINT8, + TYPE_UINT16, + TYPE_UINT32, + TYPE_UINT64, + TYPE_BLOB, + TYPE_STRING, +}; + +Because TYPE_BLOB < TYPE_STRING and delim_start[] is a static array, +delim_start[emit_type] is 0x0. The glibc usually prints out "(null)" +when one passes 0x0 to %s, but it seems to call fputs() internally if +the format is exactly "%s", hence the crash. + +TYPE_BLOB basically means the data comes from a file and we don't know +its type. We don't care for the former, and the latter is TYPE_NONE. + +So let's drop TYPE_BLOB completely and use TYPE_NONE instead when reading +the file. Then, try to guess the data type at emission time, like the +code already does for refs and labels. + +Instead of adding yet another check for TYPE_NONE, an helper is introduced +to check if the data marker has type information, ie, >= TYPE_UINT8. + +Fixes: 32b9c61307629ac76c6ac0bead6f926d579b3d2c +Suggested-by: David Gibson +Signed-off-by: Greg Kurz +Signed-off-by: David Gibson +Signed-off-by: Joel Stanley +--- + data.c | 2 +- + dtc.h | 1 - + treesource.c | 9 +++++++-- + 3 files changed, 8 insertions(+), 4 deletions(-) + +diff --git a/data.c b/data.c +index accdfaef6668..4a204145cc7b 100644 +--- a/data.c ++++ b/data.c +@@ -95,7 +95,7 @@ struct data data_copy_file(FILE *f, size_t maxlen) + { + struct data d = empty_data; + +- d = data_add_marker(d, TYPE_BLOB, NULL); ++ d = data_add_marker(d, TYPE_NONE, NULL); + while (!feof(f) && (d.len < maxlen)) { + size_t chunksize, ret; + +diff --git a/dtc.h b/dtc.h +index 303c2a6a73b7..51c03ef64dbe 100644 +--- a/dtc.h ++++ b/dtc.h +@@ -82,7 +82,6 @@ enum markertype { + TYPE_UINT16, + TYPE_UINT32, + TYPE_UINT64, +- TYPE_BLOB, + TYPE_STRING, + }; + extern const char *markername(enum markertype markertype); +diff --git a/treesource.c b/treesource.c +index f99544d72344..53e62036ad0e 100644 +--- a/treesource.c ++++ b/treesource.c +@@ -133,9 +133,14 @@ static void write_propval_int(FILE *f, const char *p, size_t len, size_t width) + } + } + ++static bool has_data_type_information(struct marker *m) ++{ ++ return m->type >= TYPE_UINT8; ++} ++ + static struct marker *next_type_marker(struct marker *m) + { +- while (m && (m->type == LABEL || m->type == REF_PHANDLE || m->type == REF_PATH)) ++ while (m && !has_data_type_information(m)) + m = m->next; + return m; + } +@@ -225,7 +230,7 @@ static void write_propval(FILE *f, struct property *prop) + size_t chunk_len; + const char *p = &prop->val.val[m->offset]; + +- if (m->type < TYPE_UINT8) ++ if (!has_data_type_information(m)) + continue; + + chunk_len = type_marker_length(m); +-- +2.17.1 +