Compare commits

...

3 Commits

4 changed files with 188 additions and 20 deletions

View File

@@ -0,0 +1,41 @@
From 1f9e2fa0b4d872fdd01ca3ba81b04dfb1211a187 Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Fri, 2 Feb 2024 09:32:48 -0500
Subject: [PATCH] Fix reversed calloc() arguments
The prototype is "void *calloc(size_t nelem, size_t elsize);"
These two instances had them reversed, almost certainly leading to
buffer overflow issues. This was detected by
-Werror=calloc-transposed-args on gcc.
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
---
src/pesigcheck.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/pesigcheck.c b/src/pesigcheck.c
index 6dc67f7..8119cf1 100644
--- a/src/pesigcheck.c
+++ b/src/pesigcheck.c
@@ -240,7 +240,7 @@ check_signature(pesigcheck_context *ctx, int *nreasons,
cert_iter iter;
- reasonps = calloc(sizeof(struct reason), 512);
+ reasonps = calloc(512, sizeof(struct reason));
if (!reasonps)
err(1, "check_signature");
@@ -281,7 +281,7 @@ check_signature(pesigcheck_context *ctx, int *nreasons,
num_reasons += 16;
- new_reasons = calloc(sizeof(struct reason), num_reasons);
+ new_reasons = calloc(num_reasons, sizeof(struct reason));
if (!new_reasons)
err(1, "check_signature");
reasonps = new_reasons;
--
2.35.3

View File

@@ -0,0 +1,78 @@
From f3cf5031560ec07b0da71a090deaa67afdffd95f Mon Sep 17 00:00:00 2001
From: Egor Ignatov <egori@altlinux.org>
Date: Fri, 26 Jan 2024 15:44:02 +0300
Subject: [PATCH] Initialize pwdata in efikeygen and pesign
Fixes: github issue #105
Fixes: 12f1671 (Rework the wildly undocumented NSS password file goo.)
Complements: 1a4481e (Add more ways to use a password with the token)
Signed-off-by: Egor Ignatov <egori@altlinux.org>
---
src/cms_common.c | 12 ++++++++----
src/efikeygen.c | 5 +++++
src/pesign.c | 2 ++
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/cms_common.c b/src/cms_common.c
index 4f4707b..1ca0b7b 100644
--- a/src/cms_common.c
+++ b/src/cms_common.c
@@ -172,8 +172,10 @@ cms_context_fini(cms_context *cms)
xfree(cms->pwdata.data);
break;
case PW_PLAINTEXT:
- memset(cms->pwdata.data, 0, strlen(cms->pwdata.data));
- xfree(cms->pwdata.data);
+ if (cms->pwdata.data) {
+ memset(cms->pwdata.data, 0, strlen(cms->pwdata.data));
+ xfree(cms->pwdata.data);
+ }
break;
}
cms->pwdata.source = PW_SOURCE_INVALID;
@@ -319,8 +321,10 @@ void cms_set_pw_data(cms_context *cms, secuPWData *pwdata)
case PW_FROMENV:
case PW_FROMFILE:
case PW_PLAINTEXT:
- memset(cms->pwdata.data, 0, strlen(cms->pwdata.data));
- xfree(cms->pwdata.data);
+ if (cms->pwdata.data) {
+ memset(cms->pwdata.data, 0, strlen(cms->pwdata.data));
+ xfree(cms->pwdata.data);
+ }
break;
case PW_DATABASE:
diff --git a/src/efikeygen.c b/src/efikeygen.c
index dd40502..010d7cc 100644
--- a/src/efikeygen.c
+++ b/src/efikeygen.c
@@ -985,6 +985,11 @@ int main(int argc, char *argv[])
if (!strcmp(dbdir, "-") && list_empty(&cms->pk12_ins) && !is_self_signed)
errx(1, "'--dbdir -' requires either --pk12-in or --self-sign.");
+ secuPWData pwdata;
+ memset(&pwdata, 0, sizeof(pwdata));
+ pwdata.source = pwdata.orig_source = PW_PROMPT;
+ cms_set_pw_data(cms, &pwdata);
+
PK11_SetPasswordFunc(cms->func ? cms->func : readpw);
if (strcmp(dbdir, "-")) {
if (cms->pk12_out.fd >= 0)
diff --git a/src/pesign.c b/src/pesign.c
index f548d81..5ac305a 100644
--- a/src/pesign.c
+++ b/src/pesign.c
@@ -395,6 +395,8 @@ main(int argc, char *argv[])
pwdata.data = strdup(secure_getenv("PESIGN_TOKEN_PIN"));
if (!pwdata.data)
err(1, "could not allocate memory");
+ } else if (pwdata.source == PW_SOURCE_INVALID) {
+ pwdata.source = PW_PROMPT;
}
pwdata.orig_source = pwdata.source;
--
2.43.0

View File

@@ -1,3 +1,42 @@
-------------------------------------------------------------------
Mon Mar 3 02:52:58 UTC 2025 - Gary Ching-Pang Lin <glin@suse.com>
- Add pesign-bsc1238023-initialize-pwdata.patch to fall back to
password prompt correctly (bsc#1238023)
-------------------------------------------------------------------
Tue Feb 25 08:02:08 UTC 2025 - JS <obs.coke518@passinbox.com>
- Enable build on loongarch64
-------------------------------------------------------------------
Tue Feb 18 10:17:39 UTC 2025 - Luca Boccassi <bluca@debian.org>
- Add Requires: mozilla-nss-tools, pesign needs it at runtime to
sign/attach signatures
-------------------------------------------------------------------
Wed Mar 20 08:44:54 UTC 2024 - Gary Ching-Pang Lin <glin@suse.com>
- Add pesign-bsc1221694-fix-reversed-calloc-arguments.patch to
fix the parameters for calloc() (bsc#1221694)
-------------------------------------------------------------------
Thu Nov 2 03:20:49 UTC 2023 - Gary Ching-Pang Lin <glin@suse.com>
- Add the Provides tag for the files moved to pesign-systemd
-------------------------------------------------------------------
Wed Nov 1 08:27:33 UTC 2023 - Gary Ching-Pang Lin <glin@suse.com>
- Move rcpesign and %{_tmpfilesdir}/pesign.conf to pesign-systemd
-------------------------------------------------------------------
Fri Oct 6 13:13:09 UTC 2023 - Dan Čermák <dcermak@suse.com>
- Create pesign-systemd subpackage to remove systemd dependency
(jsc#PED-7256)
-------------------------------------------------------------------
Wed Feb 22 08:05:20 UTC 2023 - Gary Ching-Pang Lin <glin@suse.com>

View File

@@ -1,7 +1,7 @@
#
# spec file for package pesign
#
# Copyright (c) 2023 SUSE LLC
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -39,6 +39,9 @@ Patch7: pesign-bsc1202933-Remove-pesign-authorize.patch
Patch8: pesign-bsc1202933-Make-etc-pki-pesign-writeable.patch
Patch9: pesign-fix-cert-match-check.patch
Patch10: pesign-fix-efikeygen-segfault.patch
Patch11: pesign-bsc1221694-fix-reversed-calloc-arguments.patch
# PATCH-FIX-UPSTREAM pesign-bsc1238023-initialize-pwdata.patch bsc#1238023 glin@suse.com -- Fall back to password prompt correctly
Patch12: pesign-bsc1238023-initialize-pwdata.patch
BuildRequires: efivar-devel >= 38
BuildRequires: libuuid-devel
BuildRequires: mandoc
@@ -48,25 +51,28 @@ BuildRequires: popt-devel
BuildRequires: sysuser-tools
BuildRequires: pkgconfig(systemd)
%sysusers_requires
%{?systemd_requires}
ExclusiveArch: ia64 %ix86 x86_64 aarch64 %arm riscv64
ExclusiveArch: ia64 %ix86 x86_64 aarch64 %arm riscv64 loongarch64
Recommends: %{name}-systemd
Requires: mozilla-nss-tools
%description
Signing tool for PE-COFF binaries. It is vaguely compliant
with the PE and Authenticode specifications.
%package systemd
Summary: Systemd units for pesign
Requires: %{name} = %{version}
%{?systemd_requires}
BuildArch: noarch
Provides: pesign:%{_sbindir}/rcpesign
Provides: pesign:%{_tmpfilesdir}/pesign.conf
Provides: pesign:%{_unitdir}/pesign.service
%description systemd
Systemd units for the pesign package.
%prep
%setup -q
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%autosetup -p1
%build
%sysusers_generate_pre %{SOURCE1} %{name} %{name}.conf
@@ -92,16 +98,18 @@ rm -rf %{buildroot}%{_libdir}/libdpe*
install -Dm0644 %{SOURCE1} %{buildroot}%{_sysusersdir}/%{name}.conf
%pre -f %{name}.pre
%pre systemd
%service_add_pre pesign.service
%preun
%preun systemd
%service_del_preun pesign.service
%post
%post systemd
%service_add_post pesign.service
systemd-tmpfiles --create %{_tmpfilesdir}/pesign.conf || :
%postun
%postun systemd
%service_del_postun pesign.service
%files
@@ -113,16 +121,13 @@ systemd-tmpfiles --create %{_tmpfilesdir}/pesign.conf || :
%{_bindir}/pesigcheck
%{_bindir}/authvar
%{_bindir}/pesum
%{_sbindir}/rcpesign
%dir %{_sysconfdir}/pesign
%{_sysconfdir}/pesign/*
%dir %{_sysconfdir}/popt.d
%config %{_sysconfdir}/popt.d/pesign.popt
%{_rpmmacrodir}/macros.pesign
%{_mandir}/man?/*
%{_unitdir}/pesign.service
%{_sysusersdir}/pesign.conf
%{_tmpfilesdir}/pesign.conf
%dir %{_libexecdir}/pesign
%{_libexecdir}/pesign/pesign-rpmbuild-helper
%dir %{_sysconfdir}/pki/
@@ -130,4 +135,9 @@ systemd-tmpfiles --create %{_tmpfilesdir}/pesign.conf || :
%ghost %dir %attr(0770,pesign,pesign) /run/%{name}
%dir %attr(0770,pesign,pesign) %{_localstatedir}/lib/%{name}
%files systemd
%{_sbindir}/rcpesign
%{_unitdir}/pesign.service
%{_tmpfilesdir}/pesign.conf
%changelog