From: Yusong Gao <a869920004@gmail.com>
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, a869920004@gmail.com
Cc: keyrings@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-crypto@vger.kernel.org
Subject: Re: [PATCH v5] sign-file: Fix incorrect return values check
Date: Wed, 29 Nov 2023 08:19:06 +0000 [thread overview]
Message-ID: <20231129081906.504149-1-a869920004@gmail.com> (raw)
In-Reply-To: <20231129080033.12c4efe3@smeagol>
On Wed, Nov 29, 2023 at 3:00 PM Juerg Haefliger <juergh@proton.me>
wrote:
>
> On Mon, 27 Nov 2023 03:34:56 +0000
> "Yusong Gao" <a869920004@gmail.com> wrote:
>
> > 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 <a869920004@gmail.com>
> > ---
> > V1, V2: Clarify the description of git message.
> > V3: Removed redundant empty line.
> > V4: Change to more strict check mode.
> > ---
> > 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
> >
>
> Nit: v5 in the email subject should be v4.
Yeah, thanks for point out, I get it.
>
> Reviewed-by: Juerg Haefliger <juerg.haefliger@canonical.com>
>
BR, Yusong Gao
next prev parent reply other threads:[~2023-11-29 8:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-27 3:34 [PATCH v5] sign-file: Fix incorrect return values check Yusong Gao
2023-11-29 7:00 ` Juerg Haefliger
2023-11-29 8:19 ` Yusong Gao [this message]
-- strict thread matches above, loose matches on Subject: below --
2023-12-13 10:38 David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231129081906.504149-1-a869920004@gmail.com \
--to=a869920004@gmail.com \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=dimitri.ledkov@canonical.com \
--cc=dwmw2@infradead.org \
--cc=herbert@gondor.apana.org.au \
--cc=jarkko@kernel.org \
--cc=juergh@proton.me \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lists@sapience.com \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox