Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5057674rdb; Tue, 12 Dec 2023 18:44:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEaufYUThU+5IJjgfLUMtj0RJzB7v+nIV9E4ndCpviIMGyU1WaOlQFK9crmZaW4PFbEqMSL X-Received: by 2002:a05:620a:2411:b0:77e:fba3:a7a1 with SMTP id d17-20020a05620a241100b0077efba3a7a1mr6273690qkn.127.1702435468874; Tue, 12 Dec 2023 18:44:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702435468; cv=none; d=google.com; s=arc-20160816; b=WNzqhux4SkRjVbmq6IPpb6nr+JI2KNULThhIiXKB5WcPGooqm+eXL2M7TmLYZv8oEH 6zF6J39dEBVzSz3qMD3Y6ZFjFVs3HyNTA0ffAF1vzaCUKX12ldengjHXBY3adw7wYzZC IqBf7fIsrRlwXjD7OYSuLyNgmPDASHMkwuBxjPd5y18Hf0jTfgvkRGp5LDAKSPMHFjmO 8fd3FQ3sxY2pCzqhMAH7sWF9hXJmjeVT8DoNb00+w26Z7z+jsBbYJbL06dW7JXg9KkIv BcrRCDf4WOUWjUkinuq1W0MQe+a8pKNj81YZE0Ez6R0btVCsTMrRIka9+pfPcDLFxHQZ fNcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=6EMpI1CYWqKj7MUlM6DndrADvL2mEOMt5kPq+h2tOYg=; fh=Pl/tejWQwLbqR0ccTBYwy4hG9sFCj7x403aZBBZnQJM=; b=oR4Ar3ke5LtxqbCrmH98dd2Ekaj9k9vT9lFrlg1Ezbj9V6mHE9Lmqi46sT0nfzD9e+ jaJEIk3+pkP/sOoVyuZV5f7K4haPZmdoXXzKyBe8EAKTch3wheIzUu+08U0QQ4SV/PyE gZIp8JAfcO7CsdBxwFnCFwwEuuUzo1U1hezXxg0WABgrGhWc5IxfGiVu4e5qOKUDK6E8 NbZ0r+/0w+cMUP/dF9Pb0zvgaxeYX2UcfT75LwdiMKvVAWsviGfUxVr9mzTyXP2nVC75 8VxZwePiMeMKxNlq7NG4DQ4b8cL/Zr4RY0uE/EgJYw/ADRkKgcFzen58OMbDYmzQOa45 bBEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mpiyXYjk; spf=pass (google.com: domain of linux-crypto+bounces-778-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-crypto+bounces-778-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c23-20020ae9e217000000b0077bd014247fsi11431965qkc.744.2023.12.12.18.44.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 18:44:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-778-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mpiyXYjk; spf=pass (google.com: domain of linux-crypto+bounces-778-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-crypto+bounces-778-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8E6521C20AE1 for ; Wed, 13 Dec 2023 02:44:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E0D71844; Wed, 13 Dec 2023 02:44:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mpiyXYjk" X-Original-To: linux-crypto@vger.kernel.org Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D98C3A5; Tue, 12 Dec 2023 18:44:19 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6ce7c1b07e1so5511200b3a.2; Tue, 12 Dec 2023 18:44:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702435459; x=1703040259; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=6EMpI1CYWqKj7MUlM6DndrADvL2mEOMt5kPq+h2tOYg=; b=mpiyXYjkajrjBzn5Q9eIvv0ERYmr9L+HGX0CGVo44qiVd6R91WPcokzdyOgk+FzbJG oGU67f+XSC587oH6hhpXClxYj0q0c8ynICp2lGz9hnLjGZy0uab41EUNBFrzG51Wj7A2 t+grx3pdWPkWbIT/1vraNpF4my1OGxFX28jmNCnnc3k7p0Mio1V3Pw4+zye52Ok7EEru mgOxbg1EWcmAem9JLUpQqX8w00gCYZ2jzqCgblg1jQTB5S1l1xf6Z4hrMl6H5C1b/Wqh RW/WmAfx3rEfvwxnMnb0iYk0P06U80D3cXyjwi6Qnq0NvFEaD0DmYAFreGDmjBJrbyon 1Exg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702435459; x=1703040259; 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=6EMpI1CYWqKj7MUlM6DndrADvL2mEOMt5kPq+h2tOYg=; b=L+refIUTvpKacWf4xUkohB1gWJX9fO1oUvk2MjEC30Uedig62DzNgef6J8/W5jnwki tprhXnC9vw086gFYSg3qc0cnpp/o4KVu/TtMb8lGmhLaZcwxXd9WhKfTh6B9Tvog7D/y W1nCeRvairquAoO3Ip2JvyHcHo6x/AhPB9H7xWaXWTLWAUHjQTe6makxs624YE5OL0b7 8G1HDlkEhJToIK3yXqJL9h3nMD0wx9ZXxIDyWcyEMEwqR38EvoZxAShLqzUxXNgfQcAL ItIkJE/z4fud/e+iV9PjkEJvnq55Nz4Ohqc+IoEdiyV0mVz5r0K021OLC7yaWRTnI64K QO8w== X-Gm-Message-State: AOJu0YzjtHGlGoWH+SXsmDfgWVdr3cvgRcTXiF7i4AtYdaIe5mtzJ4Re qu6daNSAaPTQ6e+nhYScbq0= X-Received: by 2002:a05:6a00:170d:b0:6ce:5431:6e43 with SMTP id h13-20020a056a00170d00b006ce54316e43mr9617190pfc.33.1702435459190; Tue, 12 Dec 2023 18:44:19 -0800 (PST) Received: from localhost.localdomain ([106.13.249.127]) by smtp.gmail.com with ESMTPSA id x20-20020aa793b4000000b006ce4c7ba448sm8839523pff.25.2023.12.12.18.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 18:44:18 -0800 (PST) From: Yusong Gao To: jarkko@kernel.org, davem@davemloft.net, dhowells@redhat.com, dwmw2@infradead.org, juergh@proton.me, zohar@linux.ibm.com, herbert@gondor.apana.org.au, lists@sapience.com, dimitri.ledkov@canonical.com Cc: keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Subject: [PATCH v5 RESEND] sign-file: Fix incorrect return values check Date: Wed, 13 Dec 2023 02:44:05 +0000 Message-Id: <20231213024405.624692-1-a869920004@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit There are some wrong return values check in sign-file when call OpenSSL API. The ERR() check cond is wrong because of the program only check the return value is < 0 which ignored the return val is 0. For example: 1. CMS_final() return 1 for success or 0 for failure. 2. i2d_CMS_bio_stream() returns 1 for success or 0 for failure. 3. i2d_TYPEbio() return 1 for success and 0 for failure. 4. BIO_free() return 1 for success and 0 for failure. Link: https://www.openssl.org/docs/manmaster/man3/ Fixes: e5a2e3c84782 ("scripts/sign-file.c: Add support for signing with a raw signature") Signed-off-by: Yusong Gao Reviewed-by: Juerg Haefliger --- V5: No change. V4: Change to more strict check mode. V3: Removed redundant empty line. V1, V2: Clarify the description of git message. --- scripts/sign-file.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/sign-file.c b/scripts/sign-file.c index 598ef5465f82..3edb156ae52c 100644 --- a/scripts/sign-file.c +++ b/scripts/sign-file.c @@ -322,7 +322,7 @@ int main(int argc, char **argv) CMS_NOSMIMECAP | use_keyid | use_signed_attrs), "CMS_add1_signer"); - ERR(CMS_final(cms, bm, NULL, CMS_NOCERTS | CMS_BINARY) < 0, + ERR(CMS_final(cms, bm, NULL, CMS_NOCERTS | CMS_BINARY) != 1, "CMS_final"); #else @@ -341,10 +341,10 @@ int main(int argc, char **argv) b = BIO_new_file(sig_file_name, "wb"); ERR(!b, "%s", sig_file_name); #ifndef USE_PKCS7 - ERR(i2d_CMS_bio_stream(b, cms, NULL, 0) < 0, + ERR(i2d_CMS_bio_stream(b, cms, NULL, 0) != 1, "%s", sig_file_name); #else - ERR(i2d_PKCS7_bio(b, pkcs7) < 0, + ERR(i2d_PKCS7_bio(b, pkcs7) != 1, "%s", sig_file_name); #endif BIO_free(b); @@ -374,9 +374,9 @@ int main(int argc, char **argv) if (!raw_sig) { #ifndef USE_PKCS7 - ERR(i2d_CMS_bio_stream(bd, cms, NULL, 0) < 0, "%s", dest_name); + ERR(i2d_CMS_bio_stream(bd, cms, NULL, 0) != 1, "%s", dest_name); #else - ERR(i2d_PKCS7_bio(bd, pkcs7) < 0, "%s", dest_name); + ERR(i2d_PKCS7_bio(bd, pkcs7) != 1, "%s", dest_name); #endif } else { BIO *b; @@ -396,7 +396,7 @@ int main(int argc, char **argv) ERR(BIO_write(bd, &sig_info, sizeof(sig_info)) < 0, "%s", dest_name); ERR(BIO_write(bd, magic_number, sizeof(magic_number) - 1) < 0, "%s", dest_name); - ERR(BIO_free(bd) < 0, "%s", dest_name); + ERR(BIO_free(bd) != 1, "%s", dest_name); /* Finally, if we're signing in place, replace the original. */ if (replace_orig) -- 2.34.1