From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id WFSgA2YIaWMNqgAAbAwnHQ (envelope-from ) for ; Mon, 07 Nov 2022 14:30:14 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id IA+0A2YIaWMkOQEA9RJhRA (envelope-from ) for ; Mon, 07 Nov 2022 14:30:14 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B3DFA10AEE for ; Mon, 7 Nov 2022 14:30:13 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1os2CT-0000wy-9E; Mon, 07 Nov 2022 08:30:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1os2CR-0000wp-DO for bug-guix@gnu.org; Mon, 07 Nov 2022 08:30:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1os2CR-0002QL-2Z for bug-guix@gnu.org; Mon, 07 Nov 2022 08:30:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1os2CQ-0002Hl-Lv for bug-guix@gnu.org; Mon, 07 Nov 2022 08:30:02 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#58732: installer: finalizers & device destroy segfault Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Mon, 07 Nov 2022 13:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58732 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: Mathieu Othacehe Cc: 58732@debbugs.gnu.org Received: via spool by 58732-submit@debbugs.gnu.org id=B58732.16678277958746 (code B ref 58732); Mon, 07 Nov 2022 13:30:02 +0000 Received: (at 58732) by debbugs.gnu.org; 7 Nov 2022 13:29:55 +0000 Received: from localhost ([127.0.0.1]:33615 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1os2CJ-0002H0-BI for submit@debbugs.gnu.org; Mon, 07 Nov 2022 08:29:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39922) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1os2CH-0002Gn-NT for 58732@debbugs.gnu.org; Mon, 07 Nov 2022 08:29:54 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1os2CC-0001OX-F5 for 58732@debbugs.gnu.org; Mon, 07 Nov 2022 08:29:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=CJmlo+Wu2GFWDM0QmQf1a45uQxaXI5DZB0eMhXakgsE=; b=pn9xtt4tbvWgrv5amPJ0 HqCyzov2t2rPc2/FIR57nkbWH4pjCuVFBouUgcZ/pvswpD8T9AYBJ/VnfrgWgodas6M6gX7D4p67f 80o1UW7SqkAEqItIqOUnSZl2M2KHxNFhAGwYMgYv57oHQiht3wId8PhglW3++sBf8HZNQJ2ZD1Ny3 Ppqg8bDWh9+VM+bzMCJcNMmU4xEXkEqkhRqynA6W4g+VgIF0rZ69V+O/SKmU0KWw/ZAkdYrDFr6rm nhHtCbvvIplE96jVqE9LdqxgLg0AithQ+USHtCP0MQP6UyC8XuGhcFPf911FBjZxBz1CeSkfWaxuk GreDs+VOhvI5HQ==; Received: from [193.50.110.147] (helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1os2CB-0003Ls-R6; Mon, 07 Nov 2022 08:29:48 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <87v8oa29ik.fsf@gnu.org> <871qqlwrpy.fsf@gnu.org> <87iljwuwf7.fsf@gnu.org> <871qqkth3g.fsf@gnu.org> <87sfiwm297.fsf@gnu.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: Septidi 17 Brumaire an 231 de la =?UTF-8?Q?R=C3=A9volution, ?= jour du Cresson X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Mon, 07 Nov 2022 14:29:45 +0100 In-Reply-To: <87sfiwm297.fsf@gnu.org> (Mathieu Othacehe's message of "Sun, 06 Nov 2022 18:17:08 +0100") Message-ID: <87iljquc3a.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: bug-guix-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1667827813; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=CJmlo+Wu2GFWDM0QmQf1a45uQxaXI5DZB0eMhXakgsE=; b=LHZn0f4Jdh2xeH4owwOX6WN7Wz1AEFjRkTguZ+e8IL8Xt/XQTM8tyYr7AiLg5HUrVVCbBc rPXIzPn82bTmWNzg8PDVyJQVx4QMcKV8m3H+YCIf4FC5GdJj5mnhGcF69PTdcqgXqpkXtY tHaD2XfBlDdQ83h1Nnasf04yub0hbo6qpKIsqKPY5AK0qhF2jT53bdPUdyJiCLMEG+uRbF y8S2kByt8i9zGj8pnXBln8NtjVAW7JScPfCbk1m4ffbAoCPEC7OmKwfEruLlpHJU1rV9VJ o8/jHOUWuLnN1W+B8wTeEv7TkfRM7cqfNa3z+Y6FG4SrIVFfb6uRytFtqhGD4Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1667827813; a=rsa-sha256; cv=none; b=ih1b2CpXt+MWyIQ4/HE0O/QQsp1JFj+I2LDPoXW5NZkT9hQXWpid9INd9Qq3NBk2riBB7B faQMYE2CRTp2hYMBh1CYRe6WQzdajI0fVlo8kbcw2Ytu6JcnR1MucThjvs2cyTPXqkR5Ft Jkb//cuM3QY4fXCV4ZqSS/v658lzDYcIYZsiEEUM2skz/7Gq0WZkmvGqO/yoBd/Ou1Mj+z nUg4mVmXnct9kKWA9YHhklTV1WY7Qc+Q5HRUuWW5iDoaOCDrp6sTThUT9fGp7rwqSLTUU3 g2e/QEfjXH8dfxO+HUX1uyZ4uQVe/OqFAUH5wqhLy9Q2clwR7BVzwnJzTR78KA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=pn9xtt4t; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.90 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=pn9xtt4t; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: B3DFA10AEE X-Spam-Score: -3.90 X-Migadu-Scanner: scn1.migadu.com X-TUID: L+HZSALqPg/m Hi Mathieu, Mathieu Othacehe skribis: > I made some progress on that one. I think, this is what's going on: > > 1. Two new PedDevice A and B are malloc'ed by the libparted when opening > the installer partitioning page. > > 2. They are added to the %devices weak hash table by pointer->device! > and their respective finalizers are registered. > > 3. The partitioning ends and A goes out of scope. It is eventually > removed from %devices but it does not mean its finalizer will be run > immediately. > > 4. The partitioning is restarted using the installer menu. B is still in > the %devices hash table. However, A is now gone and is added again to > the %devices hash table by the pointer->device! procedure. Another > finalizer is registered for A. > > That's because set-pointer-finalizer! does not *set* a finalizer it > *adds* one. Oh, I think I see what you mean. You=E2=80=99re right about =E2=80=98set-pointer-finalizer!=E2=80=99 adding a finalizer, but I don=E2= =80=99t think that=E2=80=99s what=E2=80=99s happening here. Finalizers are set on pointer objects, so they=E2=80=99re invoked when the pointer object goes out of scope. But: (eq? (make-pointer 123) (make-pointer 123)) =3D> #f So a possible mistake is to add one finalizer on each pointer object and have several pointer objects aliasing the same C object; that=E2=80=99s how= you can get the same =E2=80=9Cfree=E2=80=9D function called several times on th= e same C object. > 5. The partitioning ends and both A and B goes out of scope. They are > removed from %devices and their finalizers are called. The A finalizer > is called twice resulting in a double free. > > This race condition is created by the fact that there is a time window > where the device is removed from the %devices hash table but its > finalizer is not immediately called. What if we create an extra hashv table that maps pointer values (integers) to pointer objects? (define %pointers (make-hash-table)) (define (canonical-pointer ptr) (or (hashv-ref %pointers (pointer-address ptr)) (begin (hashv-set! %pointers (pointer-address ptr) ptr) ptr))) This is kinda terrible but it would allow us to test the above hypothesis. Thanks, Ludo=E2=80=99.