Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lc4wY-00056H-CM for mharc-grub-devel@gnu.org; Thu, 29 Apr 2021 07:34:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59996) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc4wS-00053W-9e for grub-devel@gnu.org; Thu, 29 Apr 2021 07:34:52 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:38603) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lc4wP-00074M-9u for grub-devel@gnu.org; Thu, 29 Apr 2021 07:34:46 -0400 Received: by mail-wr1-x42f.google.com with SMTP id k14so16622685wrv.5 for ; Thu, 29 Apr 2021 04:34:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=surgut.co.uk; s=google; h=sender:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=QAHJPuWU2IFIpbR109QikJF4Zmj1z7dvotcmXk7o9/c=; b=dGiwlAD0aFmPXxYQ1T6UMiC0OplTrXQqwFruspWOuHN+f98PHGwvNlNCFktR3/Vt/t N7uD7Q6am5CvAg0lUNHNJqtbKX/W6a1HOYy6hY0xTT/qRa6a95+5qLz6hawbyiKaQEIJ 2kBw8SD50rOK4BDlA7tpkKMCfbde2JCkL8Te8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :mime-version:content-transfer-encoding; bh=QAHJPuWU2IFIpbR109QikJF4Zmj1z7dvotcmXk7o9/c=; b=BBrTl+Fn7eogdp7DnL25xkhkNkSbtVORctkQud4hcR1iwmapeME8Z/tOSSaDo4FRI8 Lasdmo3cCJlyqBWU3zjYSjYLXhYQu5S3rsPMV91GgWLkQwF7CRcAbwtGdAj6E1l4zRru arE9adlka5HhnMk7q16boAAWp4eznebeYhljhL1Bm5UoTXmyAYgW9PDPVmE+Zif3RiTl LLhWxdT0IKQWSCw2o2SJuetRJMpojOqNJWTPeQPOwFLyLNrJTIMqJsB5K9oD4U/WxFka TkfJHfTw7XItWGIwdpeHjHPIVZQxtZOqhw8qQPJbrJiFOR2m0Xvv5S3g58Lxhu+Q8Ms8 /SJA== X-Gm-Message-State: AOAM5323fdVFKBV8vqG5l68VriKrJht2amR65+Mj93tcSnNjX9TSbkNq psvGF1DPDWjoMQCJsuLcZi7NZal8RJnyBg== X-Google-Smtp-Source: ABdhPJzX1EesaxnUcPApR2A48uxUzoLzWJNGwGxB1I88TwFuxm3fAdggNY3MJf1ENgDQWOK3ucVgkw== X-Received: by 2002:a5d:47ad:: with SMTP id 13mr43198390wrb.56.1619696080832; Thu, 29 Apr 2021 04:34:40 -0700 (PDT) Received: from localhost ([2a01:4b00:85fd:d700:fd94:eea5:c82d:4c74]) by smtp.gmail.com with ESMTPSA id c2sm3416191wmr.22.2021.04.29.04.34.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Apr 2021 04:34:40 -0700 (PDT) Sender: Dimitri John Ledkov From: Dimitri John Ledkov To: grub-devel@gnu.org Subject: [PATCH] unix exec: avoid atexit handlers when child execvp fails Date: Thu, 29 Apr 2021 12:34:34 +0100 Message-Id: <20210429113434.25353-1-xnox@ubuntu.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=dimitri.ledkov@surgut.co.uk; helo=mail-wr1-x42f.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Apr 2021 11:34:53 -0000 Functions `grub_util_exec_pipe()` and `grub_util_exec_pipe_stderr()` currently call `execvp()`. If the call fails for any reason, the child currently calls `exit(127)`. This in turn executes the parents `atexit()` handlers from the forked child, and then the same handlers are called again from parent. This is usually not desired, and can lead to deadlocks, and undesired behaviour. This patch fixes up "unix exec: avoid atexit handlers when child exits" further. Fixes e75cf4a58b5eaf482804e5e1b2cc7d4399df350e Signed-off-by: Dimitri John Ledkov --- grub-core/osdep/unix/exec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/osdep/unix/exec.c b/grub-core/osdep/unix/exec.c index db3259f650..e8db9202fb 100644 --- a/grub-core/osdep/unix/exec.c +++ b/grub-core/osdep/unix/exec.c @@ -188,7 +188,7 @@ grub_util_exec_pipe (const char *const *argv, int *fd) close (pipe_fd[1]); execvp ((char *) argv[0], (char **) argv); - exit (127); + _exit (127); } else { @@ -234,7 +234,7 @@ grub_util_exec_pipe_stderr (const char *const *argv, int *fd) close (pipe_fd[1]); execvp ((char *) argv[0], (char **) argv); - exit (127); + _exit (127); } else { -- 2.27.0