From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id D23951F56A for ; Mon, 11 Sep 2023 09:41:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1694425298; bh=UdrE131nT6kndDKUVP2HAcFOQuje3X6XJQZ6rsv/RWY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oPG5wkcglcVj4QKrbB20yfdljzQytKD82sHR1P1WDPuSogTp+VKEzASpwWZNGSmQO soKubKkEFRr2dHTzIKtsRY3ayG3CpU42Bwgqjp3HUq/HgR1epz3Vn435vDg9f8RptJ bt6SL3t9WmJ11874mRD8/BOIyRO7IYLHLEFYSzlE= From: Eric Wong 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 Message-ID: <20230911094132.75792-8-e@80x24.org> In-Reply-To: <20230911094132.75792-1-e@80x24.org> References: <20230911094132.75792-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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: $!";