Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 42D77C7EE2F for ; Mon, 12 Jun 2023 20:01:02 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A097D860C6; Mon, 12 Jun 2023 22:00:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="J+1DB7g/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 415CB860C6; Mon, 12 Jun 2023 22:00:57 +0200 (CEST) Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CFCB5860C6 for ; Mon, 12 Jun 2023 22:00:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=saproj@gmail.com Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4f74cda5f1dso1247955e87.3 for ; Mon, 12 Jun 2023 13:00:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686600054; x=1689192054; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=beHJ3xoOGat67NMsDrpFXLRVoe0lujXV8TsrYGYXX0A=; b=J+1DB7g/I7blOeDVaiozJ4Ov+Js2EYK6kRZiRnryiVc67enkv5bZ7ed+UYOYfJsM6A xrbsDV1K9YWNbcN7e+b4DYwTwnAwiEuSTV3YapKkaYox0Y2RuTpfe0EaAyIONPIGsHuP ntcnRjq3ES2Bs1XYVgCj+XdBUqn8eR9bt4sdgua1Q5fwsWwtTNKHvB9CBhDzV45sRgie QmOXYIKVoch5Biqc04RTIsd70/XeMvePdMQZkPJmXhmiNOEhuWFwkpSZGQWCeUqAc9Ps GJGqRSmlm5aF/LVh9SuwQOq46l1V7OBqvW9oq31lk5+zAe951RaoPKQ3J9Mcoq0yn2Lz 1CYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686600054; x=1689192054; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=beHJ3xoOGat67NMsDrpFXLRVoe0lujXV8TsrYGYXX0A=; b=NolPU5I8qtznzNj6teuxOdIECCRo5lDg2JWOr36pAFDjtO/7EjhnJm8qj6afoYWoBG my5jwp3XwXZqcV3/Ho6DpdIEPIUdWSNrulB0BfnYhV99F7Eoq7/i24yG7abL6R/MB/7z qcwOq+vt32exRqHFDfLE4RXx6uPHpD6NFDBGn7cI05Hyt7Z66LFGKiaxfa2Dcu5CVgIQ PJrgTDqhycV9wTAMjQOv0hyrglTM7+4E1SqMQCoIlBV7pZ22vV1Wpgh2GSDyJd0cjTCK csf9Ywjxugo5O3w8cJKVNDPuPRUjxRbdZB1YZH5NRCEEIIB8RBn6PQTDyivXWUcsTl76 fzjw== X-Gm-Message-State: AC+VfDxPMuKUMcMjEXMFrcSLJZwIRnAi3pUMQ8CMrU6CH4gONpN71Ya3 xMRL9ktD3s3C00Aie3CIn2dYmVhh6Yw= X-Google-Smtp-Source: ACHHUZ6wWvXDhuRTMyLuZY7gn0SW7OIIPy49QY1NUUFPSmxJkLtlttWcx0DaH6dgMnwqM1aqQcSlJw== X-Received: by 2002:ac2:4842:0:b0:4f3:f98c:77fc with SMTP id 2-20020ac24842000000b004f3f98c77fcmr4428936lfy.8.1686600053679; Mon, 12 Jun 2023 13:00:53 -0700 (PDT) Received: from saproj-Latitude-5501.lan ([83.217.200.210]) by smtp.gmail.com with ESMTPSA id i5-20020a056512006500b004f3b3f5751bsm1531729lfo.275.2023.06.12.13.00.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 13:00:53 -0700 (PDT) From: Sergei Antonov To: u-boot@lists.denx.de Cc: Sergei Antonov , Breno Lima Subject: [PATCH] hash: fix a memory leak Date: Mon, 12 Jun 2023 22:59:10 +0300 Message-Id: <20230612195910.61772-1-saproj@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean memalign() returns a pointer which is to be freed by free(). To call unmap_sysmem() is incorrect, furthermore it was called in a wrong scope. Also add a check for allocation error. Fixes: d7af2baa49c6 ("crypto/fsl: Fix HW accelerated hash commands") Cc: Breno Lima Signed-off-by: Sergei Antonov --- common/hash.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/common/hash.c b/common/hash.c index 9a52d6073ceb..cbffdfd6db36 100644 --- a/common/hash.c +++ b/common/hash.c @@ -586,6 +586,8 @@ int hash_command(const char *algo_name, int flags, struct cmd_tbl *cmdtp, output = memalign(ARCH_DMA_MINALIGN, sizeof(uint32_t) * HASH_MAX_DIGEST_SIZE); + if (!output) + return CMD_RET_FAILURE; buf = map_sysmem(addr, len); algo->hash_func_ws(buf, len, output, algo->chunk_size); @@ -602,6 +604,7 @@ int hash_command(const char *algo_name, int flags, struct cmd_tbl *cmdtp, flags & HASH_FLAG_ENV)) { printf("ERROR: %s does not contain a valid " "%s sum\n", *argv, algo->name); + free(output); return 1; } if (memcmp(output, vsum, algo->digest_size) != 0) { @@ -612,6 +615,7 @@ int hash_command(const char *algo_name, int flags, struct cmd_tbl *cmdtp, for (i = 0; i < algo->digest_size; i++) printf("%02x", vsum[i]); puts(" ** ERROR **\n"); + free(output); return 1; } } else { @@ -622,10 +626,10 @@ int hash_command(const char *algo_name, int flags, struct cmd_tbl *cmdtp, store_result(algo, output, *argv, flags & HASH_FLAG_ENV); } - unmap_sysmem(output); - } + free(output); + /* Horrible code size hack for boards that just want crc32 */ } else { ulong crc; -- 2.37.2