From patchwork Thu Jul 12 21:52:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 943242 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="fK40JjGu"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41RV6l6KX9z9rxx for ; Fri, 13 Jul 2018 07:53:03 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 858AFC21FD2; Thu, 12 Jul 2018 21:53:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8BA80C21DA2; Thu, 12 Jul 2018 21:52:57 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 743F0C21D56; Thu, 12 Jul 2018 21:52:56 +0000 (UTC) Received: from mail-lf0-f68.google.com (mail-lf0-f68.google.com [209.85.215.68]) by lists.denx.de (Postfix) with ESMTPS id 19353C21C57 for ; Thu, 12 Jul 2018 21:52:56 +0000 (UTC) Received: by mail-lf0-f68.google.com with SMTP id y200-v6so25488326lfd.7 for ; Thu, 12 Jul 2018 14:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=Ci2F9n5YN2dcoacFO0xdMAzqHklUx8GCdYfpO1fbmg8=; b=fK40JjGu2I2mmrp3qTVw0xH/tR0RIjBv1tW5mNgq+ZJmH2tcLnbHeGNJXNdVed34qf JLId8V0FBoSfLHUnkG7scYOhqknjyhn1MNOGa2Jj/iZpJcoIvhSlsCwywZr/0JGCUceb RXSV+aIGAzrTU980sju2347jfFnrXYn0KUbNs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Ci2F9n5YN2dcoacFO0xdMAzqHklUx8GCdYfpO1fbmg8=; b=VhRZPPvr5f8SZhvIkdusJuNGmehzQa+LqmXVi3HmAt7pmObiF2VKslc3CpeFx/RVnZ H3XIt1F7kmqF03apk+hV049/MVTRkoZwBzxVVD5Mj0oyJd1sLBxPxCnpPgpZxVja7bZm J0SCV6g+l+djdQo6vbatERXXXdn/TbCbjQEFCGPVbntzFz6rSDyp0v4/rH/TvquP8k8s jVCjR6j/lOzvZTahJZHjHdtaYC4MBblbznXb9RbdPMQbMoIOYVHou0y0aTGF3rTu6bQI Y2gBwNNx2c6xf1gw4KMFtNNYuoksnB/Nzv3sYZyZrEKNqNLEWUm1XEHzAr1bLWmILeqM lqaA== X-Gm-Message-State: AOUpUlHZZ/TYLVwp533MF/L2r6TticsdHWdbfF7x28nmODPz/pGP4qUz 5tASeNWJw/yElHeMBsy3zEb8JnslrSs= X-Google-Smtp-Source: AAOMgpeqsvdv658RJMK5oPtN1j6KVoOR23n5LeU39EiSSxqlJblhx4yRGI6bWTDz00Lzn4IGsT+2pA== X-Received: by 2002:a19:4344:: with SMTP id m4-v6mr3231065lfj.111.1531432375084; Thu, 12 Jul 2018 14:52:55 -0700 (PDT) Received: from localhost ([195.238.92.132]) by smtp.gmail.com with ESMTPSA id p24-v6sm3537223lje.0.2018.07.12.14.52.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Jul 2018 14:52:54 -0700 (PDT) From: Sam Protsenko To: u-boot@lists.denx.de Date: Fri, 13 Jul 2018 00:52:51 +0300 Message-Id: <20180712215253.4290-1-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.18.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 1/3] dfu: Fix data abort in dfu_free_entities() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" In case of error in dfu_config_entities(), it frees "dfu" array, which leads to "data abort" in dfu_free_entities(), which tries to free the same array (and even tries to access it from linked list first). The issue occurs e.g. when partition table on device does not match $dfu_alt_info layout: => dfu 0 mmc 1 list Couldn't find part #2 on mmc device #1 DFU entities configuration failed! data abort To fix this issue, do not free "dfu" array in dfu_config_entities(). It will be freed later in dfu_free_entities(). Signed-off-by: Sam Protsenko Acked-by: Lukasz Majewski --- drivers/dfu/dfu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index e7c91193b9..a3c09334b7 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -462,7 +462,7 @@ int dfu_config_entities(char *env, char *interface, char *devstr) ret = dfu_fill_entity(&dfu[i], s, alt_num_cnt, interface, devstr); if (ret) { - free(dfu); + /* We will free "dfu" in dfu_free_entities() */ return -1; } From patchwork Thu Jul 12 21:52:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 943243 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="VP+EXhTY"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41RV7f6WBdz9rxx for ; Fri, 13 Jul 2018 07:53:50 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 98DF7C21FC2; Thu, 12 Jul 2018 21:53:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3753CC21FC5; Thu, 12 Jul 2018 21:53:02 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 01496C21E7E; Thu, 12 Jul 2018 21:52:59 +0000 (UTC) Received: from mail-lf0-f68.google.com (mail-lf0-f68.google.com [209.85.215.68]) by lists.denx.de (Postfix) with ESMTPS id 864EAC21D56 for ; Thu, 12 Jul 2018 21:52:57 +0000 (UTC) Received: by mail-lf0-f68.google.com with SMTP id a134-v6so25468388lfe.6 for ; Thu, 12 Jul 2018 14:52:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=z/Zp2sXUf6MTt31h9qQF1whfdNvlIu9/DyEhonIqC9o=; b=VP+EXhTYfOAPjoYOT6kiZNFaCGJvfp8+70v7hVv2i+pwd3QVdLMDO1jZ1l+5idL+de Qz+ubhuIHELpJf1BfteM4yQbTVlI3xS+OemmPJqTGFWgZI1/4xnTesdLBNrGEpSXH4uL dZRxpCfwIoO7ydHLGTuyuDe7SNa6TRw9gC3z4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=z/Zp2sXUf6MTt31h9qQF1whfdNvlIu9/DyEhonIqC9o=; b=XD50fB3i+5cEWEBaFxUppiwJfIzNiN3WwTi4lIfGgYL6Z2VUppI+8b786hhFPBCjH5 l+/lCokuX+tLkUhwaLSsNdlVtfgbI7PBFclzx25iqB+xBWYnYWG12bvDoA7JgURq5puB xILoZnISXlH6eE5U3zgMn2A3BqOM5StiUb4GrmtdLa48c1dQKQijiuUP6fcWZmh9eTL2 ytRCKAFs5U21V9yTKhbSnJ8cP2K84awvvCIjMfWfEZSyIoM6f0glStq1IvJc3cp+/zDQ /ykX3q0PphlxSIQ3iQZ4EqkwnEtv8uh0oma8Ey1xD790fD4A73EQAV20qR1EFNFRcdsP UUXg== X-Gm-Message-State: AOUpUlFgf0Onn94FMcVvZeoK+zG6XXjm++n35gOfUfErhbDQtrvnAp3w q0LdgnJ1Lk9UuoHRxkYDR4W94dHYP9M= X-Google-Smtp-Source: AAOMgpf2UUXqUEsKF/C54URldJHhmkobHNt0G+6W+5R4qsgROHGKpeBfSuO8Kne/2lStOSiV31BveA== X-Received: by 2002:a19:dd81:: with SMTP id w1-v6mr2944363lfi.114.1531432376760; Thu, 12 Jul 2018 14:52:56 -0700 (PDT) Received: from localhost ([195.238.92.132]) by smtp.gmail.com with ESMTPSA id p88-v6sm3495940ljp.90.2018.07.12.14.52.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Jul 2018 14:52:56 -0700 (PDT) From: Sam Protsenko To: u-boot@lists.denx.de Date: Fri, 13 Jul 2018 00:52:52 +0300 Message-Id: <20180712215253.4290-2-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180712215253.4290-1-semen.protsenko@linaro.org> References: <20180712215253.4290-1-semen.protsenko@linaro.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 2/3] dfu: Fix memory leak in dfu_init_env_entities() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" In case of error in dfu_init_env_entities(), env_bkp will leak. Fix it by providing single return path. Signed-off-by: Sam Protsenko Acked-by: Lukasz Majewski --- drivers/dfu/dfu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index a3c09334b7..5b9abd685d 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -56,7 +56,7 @@ int dfu_init_env_entities(char *interface, char *devstr) { const char *str_env; char *env_bkp; - int ret; + int ret = 0; #ifdef CONFIG_SET_DFU_ALT_INFO set_dfu_alt_info(interface, devstr); @@ -71,11 +71,12 @@ int dfu_init_env_entities(char *interface, char *devstr) ret = dfu_config_entities(env_bkp, interface, devstr); if (ret) { pr_err("DFU entities configuration failed!\n"); - return ret; + goto done; } +done: free(env_bkp); - return 0; + return ret; } static unsigned char *dfu_buf; From patchwork Thu Jul 12 21:52:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 943244 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="WUokB4sR"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41RV8D19Qqz9rxx for ; Fri, 13 Jul 2018 07:54:20 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D4D5AC21E7E; Thu, 12 Jul 2018 21:53:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id E68A8C21FC1; Thu, 12 Jul 2018 21:53:08 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 297CDC21F69; Thu, 12 Jul 2018 21:53:04 +0000 (UTC) Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by lists.denx.de (Postfix) with ESMTPS id 33C3CC21FA0 for ; Thu, 12 Jul 2018 21:52:59 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id u7-v6so20453869lji.3 for ; Thu, 12 Jul 2018 14:52:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CncAm6Mq9V9tX6/19+coi07ISJDQjk0kgyWPG7YPTP4=; b=WUokB4sRIqI/Hn3ZIzc6sVkt2xxOieJq3Seu8pm/Kr1fwuY5HTe4cPKTvkq2dYx/p0 n+Np+lmObOWbq/zy/NjK3zZ7ZQW5oxVlrrXmaczNNc70D8zPYHqhrp2M1h60Vb0TGV/R axDMnjE8yLQ1qttmaPEOZd5RTyQlmB8TINZRA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CncAm6Mq9V9tX6/19+coi07ISJDQjk0kgyWPG7YPTP4=; b=d+6eG6c4wbfSoO9Azao8g3b3C4DCPKwrqjxnZoIRqu7TmzKvU+c8WeAJ2//+HXWwzR i7F79uY7nzhpYKWp/XXOZLbFDuZgWNjMSuA2zJ75lN9WtVDGZZ0Uh5Fnut190KQpDUZ9 C0xnucLi1TtHb7+0Ad5/Bon7xQ4XW5YKWgFfwzynoBtlEogRFPNNgVyy2UZJIyUC4+m0 xCOxMg+rtvNuI27yGMr6fVp0dkjtETRIWEU1yKPsJpkoTXQCSw+7qrKRZ/6GhfWZDY14 NK359GYEzc59I60/4xxFbvMkmLCBPATc7u03iJjCKybKMu65O/iSxScSvoyxxmuEdG8P X8qw== X-Gm-Message-State: AOUpUlEWn5XCuYatkxxmHMe6BgW0XZeutF1O/1bswI1A82HSGN93m+z5 xJTfdvIZlzBHiND7F6EYA/e/Vtx6wqs= X-Google-Smtp-Source: AAOMgpdV4w0riB6o5BtTGssTLhP2uViGNV19igOjWL1F4fNA1AkS9vBr5Lnae/CEgWqj5+Ea6yZk6w== X-Received: by 2002:a2e:144f:: with SMTP id 15-v6mr1555030lju.122.1531432378370; Thu, 12 Jul 2018 14:52:58 -0700 (PDT) Received: from localhost ([195.238.92.132]) by smtp.gmail.com with ESMTPSA id b3-v6sm6267021lfg.43.2018.07.12.14.52.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Jul 2018 14:52:57 -0700 (PDT) From: Sam Protsenko To: u-boot@lists.denx.de Date: Fri, 13 Jul 2018 00:52:53 +0300 Message-Id: <20180712215253.4290-3-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180712215253.4290-1-semen.protsenko@linaro.org> References: <20180712215253.4290-1-semen.protsenko@linaro.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 3/3] dfu: Provide more verbose error message X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" It might be useful for user to see some human-readable root cause message in addition to "configuration failed" message, so that the issue can be fixed quickly. Signed-off-by: Sam Protsenko Acked-by: Lukasz Majewski --- drivers/dfu/dfu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index 5b9abd685d..318949529b 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -71,6 +71,7 @@ int dfu_init_env_entities(char *interface, char *devstr) ret = dfu_config_entities(env_bkp, interface, devstr); if (ret) { pr_err("DFU entities configuration failed!\n"); + pr_err("(partition table does not match dfu_alt_info?)\n"); goto done; }