From patchwork Thu Feb 22 23:18:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Hellermann X-Patchwork-Id: 10236579 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E1C2C602DC for ; Thu, 22 Feb 2018 23:18:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D33E929068 for ; Thu, 22 Feb 2018 23:18:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C606E2906A; Thu, 22 Feb 2018 23:18:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4C2B228D34 for ; Thu, 22 Feb 2018 23:18:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SbpS3pv7iBNMNgJuc81RLS+V2VKUSLQMPMxCLWT7yA0=; b=bHfXGeifW1nT7rzpy1dCQTn3V 8+c/qCnWkYpLJQJl/+3BZ4imjE62Pv4+OOmpLEeyHlYYYNtn/Xf5XDClJ1je2s0GgYNVSsJwOXqvZ 8pue4vY73po7C2ltEgWH7pdR6KDEWk1QIM82kffzl5uysfyqnEBiY0BZ6lLP/3NLNll69E19+RTjf S1Cjo5F/UxG+2Ss38vQCahwzOOxcmsCV66DCBOV3rkUwCfwL+Ax8H3AQG088SPWQMLzmYKLdM+lvI SWHQVMJSy52bnAJbr4lbk47kp4V6Uwezy6ja5+mXXrchM7ZcSkDmAzs0XJPECFkAsLukEL+0OZdZe 19t/iWN2w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ep08J-0007aS-KR; Thu, 22 Feb 2018 23:18:35 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ep08F-0007Yc-9F for linux-arm-kernel@lists.infradead.org; Thu, 22 Feb 2018 23:18:33 +0000 Received: by mail-wm0-x235.google.com with SMTP id t82so1381980wmt.5 for ; Thu, 22 Feb 2018 15:18:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=the2masters.de; s=mail; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=uBuKa9B25wY9GmavRladBy30Da9XYmZz2ELJGI270HI=; b=RO+0S94K4uCelPC26CT+IvNqbCPJdBFcGvYVABV/FMDtdVEajm4ilqCLVLrFFZCqym V7ho7i18y594GAgvOhNj2nddmyVC85PLWF8VEnVp1f8a/Ogb4Av6XPpzxFV3vjXPBkH8 homVsY6fOL3SqMcuBFCI6FgRsOyTR0UWeZNik= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=uBuKa9B25wY9GmavRladBy30Da9XYmZz2ELJGI270HI=; b=tKBQBf/PbAGY8YmoaHgPlNSh461/l6Otqehxcwhh9b1TzJCKF1rAiIYuTuIESIQ7EZ mccydabKC99P7oPYCD2XHoEaieDZG7qDIgzcsc2SOArF56A5O1LmLP+mHc3yaoo1ixuc jEQBK+GPLov8Vp6TzSUhbSGsr/7vTDvjq+IqtBraMAyY+hjc/OBe47x62qik4moVknyw zJi+lnezYCv2rfUNIEZZw4pBVTnRHH05/9HOdrhsMTVDhrnmdYN3HsHOZ36+RBUURESy 4W50gFTtkEX0wjzNqu6ZgvAY0CKlRnpdNLpJ50rPRrOIjz59xzYkf+9ea1BOWoFWZmDk 1Raw== X-Gm-Message-State: APf1xPBCyO5jmGd0TUuTlGidqn7dfcupKTuJiBm0xXc+S55UH64O0h6b UthQ3JVmRWEVRgsOvFQUyOAzTdDzPwk= X-Google-Smtp-Source: AG47ELt/+2u14MVU+quYGf7iSiuyJSrycZKbxondUOYPnFM3ofzbbVBnxniUEDllGkzzzxPM3Utwmw== X-Received: by 10.28.21.136 with SMTP id 130mr71253wmv.152.1519341499137; Thu, 22 Feb 2018 15:18:19 -0800 (PST) Received: from hel-stefan.melli.lan (ip-109-90-157-220.hsi11.unitymediagroup.de. [109.90.157.220]) by smtp.googlemail.com with ESMTPSA id p104sm1577741wrb.47.2018.02.22.15.18.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Feb 2018 15:18:17 -0800 (PST) Subject: Re: [v2,1/1] ARM: orion5x: use mac_pton() helper To: Andrew Lunn References: <1443795153-40836-1-git-send-email-andriy.shevchenko@linux.intel.com> <099870d3-e2bd-aad9-d526-5438596bb575@the2masters.de> <20180222214237.GH28112@lunn.ch> From: Stefan Hellermann Message-ID: Date: Fri, 23 Feb 2018 00:18:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180222214237.GH28112@lunn.ch> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180222_151831_386363_70BF3AD7 X-CRM114-Status: GOOD ( 27.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Russell King , Jason Cooper , Detlef Vollmann , Gregory CLEMENT , Andy Shevchenko , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Am 22.02.2018 um 22:42 schrieb Andrew Lunn: > On Thu, Feb 22, 2018 at 06:45:51PM +0100, Stefan Hellermann wrote: >> Hi! >> >> My QNAP TS-209 NAS Device is crashing with the following commit, which went >> in the kernel as commit 4904dbda41c860fd117b20f3c48adb2780eee37e >> >> I cannot provide a boot log, the device panics before enabling the serial >> console. > Hi Stefan > > Did you try earlyprintk? You might need to recompile your kernel to > enable it. Yes, I tried it, but it didn't help. I even changed qnap_ts209_init() to configure uart before ethernet, but it didn't help either. > > Looking at the code, i don't see anything obviously wrong. So i think > i would start by looking how many times it goes through the loop in > qnap_tsx09_find_mac_addr() with this patch reverted, and what address > it finds the MAC address at. > > Then see what happens with the current crashing code. Is it failing to > recognise the MAC address, and so keep looping around? I think I found the failure: The code is looping through an ext2 filesystem on a 384kB mtd partition (factory configuration put there by QNAP). There it looks on every 1kB boundary if there is a valid MAC address. The filesystem has a 1kB block size, so this seems to work. The MAC address is on the 37th 1kB block. But: On the 27th block is a large file (1,5kB) without 0 bytes inside. The code in qnap_tsx09_find_mac_addr() maps 1kB into memory (not a whole file or the whole 384kB) and then calls qnap_tsx09_check_mac_addr() -> mac_pton() -> strlen() on this memory block. as there is no 0 byte in the file on the 27th block, strlen runs into bad memory and the machine panics. The old code had no strlen(). I changed mac_pton() to use strnlen(), and now the panic is gone. I don't know why strlen is actually needed in mac_pton. The string is checked in the following loop, if there is a zero byte somewhere, the loop will be returned immediately. So I think the strlen() superfluous. Is the following patch correct? diff --git a/lib/net_utils.c b/lib/net_utils.c index 148fc6e99ef6..e7785cf20f59 100644 --- a/lib/net_utils.c +++ b/lib/net_utils.c @@ -7,10 +7,6 @@ bool mac_pton(const char *s, u8 *mac)  {      int i; -    /* XX:XX:XX:XX:XX:XX */ -    if (strlen(s) < 3 * ETH_ALEN - 1) -        return false; -      /* Don't dirty result unless string is valid MAC. */      for (i = 0; i < ETH_ALEN; i++) {          if (!isxdigit(s[i * 3]) || !isxdigit(s[i * 3 + 1]))