Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1695307imm; Sun, 23 Sep 2018 09:34:17 -0700 (PDT) X-Google-Smtp-Source: ACcGV62D6xdH06uokZYwUTzrk6tco89ijeP098HzEgGGVuhZqLZLt96Vo4R/XQqbhw891NMs1N9i X-Received: by 2002:a17:902:6e4:: with SMTP id 91-v6mr7141353plh.226.1537720457748; Sun, 23 Sep 2018 09:34:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537720457; cv=none; d=google.com; s=arc-20160816; b=NjoQl2chccthRw8S7MQ3ZWXEMOMi7K4zbSVdf//SSc7VTjG7k7g5m4VEJGix7h4NNW TT2mQsLF+YGpYnww4awgrY7JNsG+nhn8Lwe9qBOVsZsP0Rvi08VzLreSqltrzML32CAA ln8TEEdtZwHMKTtqkEJQ3juyZMMcVsKBqrBhLB1yCad6eArCBNU1VaZfUT7iK3cSw+qk w1XJupNon5RGEkLxfSOL28pM1cmCu/awtJQJcYmQEdZeoN1nrBTyr0tPsk66QBnlEX2B aZ6n4EC5fT6niLxaWQbCx++Jv2kLBfnJAYkjiBVix3hUZdz0fRrfq9UrZF3n4/pcWT5/ zlCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=zPkK1bfV40IkD5P4uGcAa8dNbOFSTAmN+IYRbebQqnU=; b=XTyPspaM049Q8xOqHWik3hxkNe45CREEl+kb5cRfKMTwmNhbCWFwya5jd1ii0fULoK /XKr3F3jzGMA15J0hXA4dps27DJjCs92UXi3/B0O/Y3APkDanc5voKpdhY0IYq4nyadA fEU6jkGI4kBEPKmsobOOMSRrO2Zotikf1E68SEWDGm00vaBhIS/Wn7pL6UXwki9HcrLc Xo1d/HRC9Dk4WzbmmPN7mHB3kZ0t/ypdfX0EdNsdDlSKpnCP6mBWIrUbhy4Wlp3s86S2 0IiZUESgLTOdhnUUUn/xiLNTWp8Jq7Z4l7e6j3UuuYIeA0qZEQqaCeKw+pav/IhQz0s1 0DCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=r60tJHTA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z68-v6si34108937pfz.163.2018.09.23.09.34.01; Sun, 23 Sep 2018 09:34:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=r60tJHTA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726401AbeIWWbj (ORCPT + 99 others); Sun, 23 Sep 2018 18:31:39 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40992 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726214AbeIWWbi (ORCPT ); Sun, 23 Sep 2018 18:31:38 -0400 Received: by mail-pg1-f194.google.com with SMTP id z3-v6so3151672pgv.8; Sun, 23 Sep 2018 09:33:36 -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=zPkK1bfV40IkD5P4uGcAa8dNbOFSTAmN+IYRbebQqnU=; b=r60tJHTA/30twb4wilx+/A/pOQZ9G1TEH9XybtGK6bYvM0V8h0qxPa9pW8Zbm7Qe2I nUVIa3QUU4REVv73UierddYI28RsBEtZpgJwtUiMTyHEHlifJ70MVR7rd2cc0BMya9BW l2o0+Mpqf1RojpwxS/+e1ok8/EtrLy0B43Y5K/C0vrlZr8aJdQmAg9y6vOctAAGxwEVV 2zQPO/Er8xsoj0zUM03uVyhaIYiSBDYiRqzByOFTXI5NwuZffc24Gsftf6Bt/RFoe+yo KwZz6glAx/+3BItxfxT9D9XMIpkrb8N9exZS1Y8avop8T1MsOSsjgGg7TxJ7gbJPBh7J GiKg== 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=zPkK1bfV40IkD5P4uGcAa8dNbOFSTAmN+IYRbebQqnU=; b=fgpj4aEmnTPIQCB8SX4sYMTpu5Gr1xHTypCRJZvbosFr35AWo6gsZpnQ6xNeitRPwI 8a3iD1nF/RA5XJwMjdfI+9zXo26X/DC2Ai2h7N2NOyarLc0AOzg5k2Li0R2fpaUJUVEe 0PGmliqA7abIt9IDkSS1Q7baUonq2h14djUw6yQ6fIN8/E8N5Rb9XCdHazxbjI2Oy2cP aYs2H9u3LJ6xwYqN5nokgByolrwQ9FVgX5VB6PB6GcrFp1amzs8xRpi4vFkxpgrc60ud BYqNyXyiRqTENXv1AtBA5aShI71wc9jP74sdHd00FqpeYMpk2XBrZoVmmbPEejZExtUf 799A== X-Gm-Message-State: ABuFfojcT/q+4INf+AzfHDY/HXFNog4oL/buhy0ng/RWDLWkpePFarzu Oyzb5JeeFzQBrya6aN6kGTc= X-Received: by 2002:a63:e756:: with SMTP id j22-v6mr6455848pgk.185.1537720416435; Sun, 23 Sep 2018 09:33:36 -0700 (PDT) Received: from localhost (108-223-40-66.lightspeed.sntcca.sbcglobal.net. [108.223.40.66]) by smtp.gmail.com with ESMTPSA id t84-v6sm5435100pfj.7.2018.09.23.09.33.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Sep 2018 09:33:35 -0700 (PDT) From: Guenter Roeck To: Rob Herring Cc: Frank Rowand , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck Subject: [PATCH] of: unittest: Don't dereference args.np after test errors Date: Sun, 23 Sep 2018 09:33:32 -0700 Message-Id: <1537720412-29919-1-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a devicetree parse function fails, it is quite likely that args.np is invalid. Trying to dereference it will then cause the system to crash. This was seen when trying to run devicetree unittests on a g3beige qemu system. This system has the OF_IMAP_OLDWORLD_MAC flag set in of_irq_workarounds and expects an 'old style' structure of irq nodes. Trying to parse the test nodes fails and results in the following crash. OF: /testcase-data/phandle-tests/consumer-b: arguments longer than property Unable to handle kernel paging request for data at address 0x00bc616e Faulting instruction address: 0xc092437c Oops: Kernel access of bad area, sig: 11 [#1] BE PREEMPT PowerMac Modules linked in: CPU: 0 PID: 1 Comm: swapper Not tainted 4.19.0-rc4-yocto-standard+ #1 NIP: c092437c LR: c0925098 CTR: c0925088 REGS: cf8dfb40 TRAP: 0300 Not tainted (4.19.0-rc4-yocto-standard+) MSR: 00001032 CR: 82004044 XER: 00000000 DAR: 00bc616e DSISR: 40000000 GPR00: c0925098 cf8dfbf0 cf8e0000 c14098c7 c14098c7 c1409c50 00000066 00000002 GPR08: 00000063 00bc614e c0b483e9 000affff 82004048 00000000 00000008 c0b36d80 GPR16: c0ac0000 c0b4233c c14098c7 c0b13c14 05ffffff 000affff c0b483e4 c0b00a30 GPR24: cecfe324 cecfe324 c0acc434 c0ac8420 c1409c50 05ffffff c1409c50 c14098c7 NIP [c092437c] device_node_gen_full_name+0x30/0x15c LR [c0925098] device_node_string+0x190/0x3c8 Call Trace: [cf8dfbf0] [c0733704] of_find_property+0x5c/0x74 (unreliable) [cf8dfc30] [c0925098] device_node_string+0x190/0x3c8 [cf8dfca0] [c092690c] pointer+0x274/0x4d4 [cf8dfcd0] [c0926e20] vsnprintf+0x2b4/0x5ec [cf8dfd30] [c0927170] vscnprintf+0x18/0x48 [cf8dfd40] [c008eb70] vprintk_store+0x4c/0x22c [cf8dfd70] [c008f1c4] vprintk_emit+0x94/0x270 [cf8dfda0] [c008fb60] printk+0x5c/0x6c [cf8dfde0] [c0bd1ec0] of_unittest+0x2670/0x2b48 [cf8dfe80] [c0004ba8] do_one_initcall+0xac/0x320 [cf8dfee0] [c0b8975c] kernel_init_freeable+0x328/0x3f0 [cf8dff30] [c00050c4] kernel_init+0x24/0x118 [cf8dff40] [c0014278] ret_from_kernel_thread+0x14/0x1c To avoid this and similar problems, don't try to dereference args.np after devicetree parse failures, and display the name of the parsed node instead. With this, we get error messages such as dt-test ### FAIL of_unittest_parse_interrupts():791 index 0 - data error on node /testcase-data/interrupts/interrupts0 rc=-22 This may not display the intended node name, but it is better than a crash. Fixes: 53a42093d96ef ("of: Add device tree selftests") Signed-off-by: Guenter Roeck --- drivers/of/unittest.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 722537e14848..5942ddce1b9f 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -424,7 +424,7 @@ static void __init of_unittest_parse_phandle_with_args(void) } unittest(passed, "index %i - data error on node %pOF rc=%i\n", - i, args.np, rc); + i, np, rc); } /* Check for missing list property */ @@ -554,8 +554,8 @@ static void __init of_unittest_parse_phandle_with_args_map(void) passed = false; } - unittest(passed, "index %i - data error on node %s rc=%i\n", - i, args.np->full_name, rc); + unittest(passed, "index %i - data error on node %pOF rc=%i\n", + i, np, rc); } /* Check for missing list property */ @@ -788,7 +788,7 @@ static void __init of_unittest_parse_interrupts(void) passed &= (args.args[0] == (i + 1)); unittest(passed, "index %i - data error on node %pOF rc=%i\n", - i, args.np, rc); + i, np, rc); } of_node_put(np); @@ -834,7 +834,7 @@ static void __init of_unittest_parse_interrupts(void) passed = false; } unittest(passed, "index %i - data error on node %pOF rc=%i\n", - i, args.np, rc); + i, np, rc); } of_node_put(np); } @@ -904,7 +904,7 @@ static void __init of_unittest_parse_interrupts_extended(void) } unittest(passed, "index %i - data error on node %pOF rc=%i\n", - i, args.np, rc); + i, np, rc); } of_node_put(np); } -- 2.7.4