user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 7/7] spawn: do not block ABRT/BUS/ILL/SEGV signals
Date: Mon, 11 Sep 2023 09:41:32 +0000	[thread overview]
Message-ID: <20230911094132.75792-8-e@80x24.org> (raw)
In-Reply-To: <20230911094132.75792-1-e@80x24.org>

SIGABRT, SIGBUS, SIGILL, and SIGSEGV may all happen if we
introduce bugs in the section where signals are blocked.

We can delay handling of SIGFPE, SIGXCPU and SIGXFSZ since
there's no floating point operations; while SIGXCPU and
SIGXFSZ are safe to delay, especially in the absence of
threads in our current code paths.
---
 lib/PublicInbox/Spawn.pm   | 11 ++++++++---
 lib/PublicInbox/SpawnPP.pm |  4 ++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm
index 17d87f57..ed698afc 100644
--- a/lib/PublicInbox/Spawn.pm
+++ b/lib/PublicInbox/Spawn.pm
@@ -92,18 +92,23 @@ int pi_fork_exec(SV *redirref, SV *file, SV *cmdref, SV *envref, SV *rlimref,
 	sigset_t set, old;
 	int ret, perrnum;
 	volatile int cerrnum = 0; /* shared due to vfork */
-	int chld_is_member;
+	int chld_is_member; /* needed due to shared memory w/ vfork */
 	I32 max_fd = av_len(redir);
 
 	AV2C_COPY(argv, cmd);
 	AV2C_COPY(envp, env);
 
 	if (sigfillset(&set)) return -1;
+	if (sigdelset(&set, SIGABRT)) return -1;
+	if (sigdelset(&set, SIGBUS)) return -1;
+	if (sigdelset(&set, SIGFPE)) return -1;
+	if (sigdelset(&set, SIGILL)) return -1;
+	if (sigdelset(&set, SIGSEGV)) return -1;
+	/* no XCPU/XFSZ here */
 	if (sigprocmask(SIG_SETMASK, &set, &old)) return -1;
 	chld_is_member = sigismember(&old, SIGCHLD);
 	if (chld_is_member < 0) return -1;
-	if (chld_is_member > 0)
-		sigdelset(&old, SIGCHLD);
+	if (chld_is_member > 0 && sigdelset(&old, SIGCHLD)) return -1;
 
 	pid = vfork();
 	if (pid == 0) {
diff --git a/lib/PublicInbox/SpawnPP.pm b/lib/PublicInbox/SpawnPP.pm
index d6c863f8..e7174d6f 100644
--- a/lib/PublicInbox/SpawnPP.pm
+++ b/lib/PublicInbox/SpawnPP.pm
@@ -15,6 +15,10 @@ sub pi_fork_exec ($$$$$$$) {
 	my $old = POSIX::SigSet->new();
 	my $set = POSIX::SigSet->new();
 	$set->fillset or die "sigfillset: $!";
+	for (POSIX::SIGABRT, POSIX::SIGBUS, POSIX::SIGFPE,
+			POSIX::SIGILL, POSIX::SIGSEGV) {
+		$set->delset($_) or die "delset($_): $!";
+	}
 	sigprocmask(SIG_SETMASK, $set, $old) or die "SIG_SETMASK(set): $!";
 	my $syserr;
 	pipe(my ($r, $w)) or die "pipe: $!";

      parent reply	other threads:[~2023-09-11  9:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11  9:41 [PATCH 0/7] system-related updates and cleanups Eric Wong
2023-09-11  9:41 ` [PATCH 1/7] tests: map CLOFORK->FD_CLOEXEC temporarily for `tail -f' Eric Wong
2023-09-11  9:41 ` [PATCH 2/7] daemon: depend on DS event_loop in master process, too Eric Wong
2023-09-11  9:41 ` [PATCH 3/7] ds: use object-oriented API for epoll Eric Wong
2023-09-11  9:41 ` [PATCH 4/7] favor poll(2) for most daemons Eric Wong
2023-09-11  9:41 ` [PATCH 5/7] dspoll: switch to the documented IO::Poll API Eric Wong
2023-09-12  2:34   ` Eric Wong
2023-09-12  6:13     ` [PATCH 8/7] provide select(2) backend for PublicInbox::DS Eric Wong
2023-09-11  9:41 ` [PATCH 6/7] ds: use constants for @UNBLOCKABLE list Eric Wong
2023-09-11  9:41 ` Eric Wong [this message]

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

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230911094132.75792-8-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).