From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 48AFE3858C54 for ; Fri, 12 May 2023 10:19:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 48AFE3858C54 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683886781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=IwS1TRaqSyYArHWaQB2G+LvZXL0icxcYMI1R1vf76oI=; b=inJKdBm9MnVGD2S3nffzb27TaxDFhdSA0YG6RVhXVgiV6F069xoNzplwFaHz1pxeyFNuDL Y7Y3nz/oUOUsirkDzJp5oG5b1pn7Op5BsB+nBJQIJI/vPqJW3/SFGO/1Sl2xgPor2TsxI/ e0fOkmMddRWbuef5LoZS5C3DSI88qsU= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-509-cVVOjEASN3qQ0d2j4_jKbQ-1; Fri, 12 May 2023 06:19:39 -0400 X-MC-Unique: cVVOjEASN3qQ0d2j4_jKbQ-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3f4ef4bf00dso8404555e9.1 for ; Fri, 12 May 2023 03:19:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683886778; x=1686478778; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IwS1TRaqSyYArHWaQB2G+LvZXL0icxcYMI1R1vf76oI=; b=eNxMlcGrU/FndsaWF5UYoDYJWn2KoIwYZS4ZKO/8fKtw8TEMaMAq11+qUmcGA+U8qV leTCWG/qLsqE+XY0Wl2baPmDCMsddEd0ATdtkakM7uJuqPbDUcnD1jcTDfMSGXqIUxiG awcTENwsNK7HBYGl8oKyex3IzfCotqdwslr7gG4nycMMKEAd/AnQvOt7Tc+nAlDp5IBX 8qTAsTJNpUtSXylohNk/wlqcNvePjokbGHz1MHnnYZWxh2jOqfHMjDmjewK7GPrxkG8e OGMHdGdCavTDeSlwY2MOl318xEdiZmUiH9x/bTVr4BIgs5UzeBGvrogmqzBKrxXvUo2k b/iw== X-Gm-Message-State: AC+VfDxC541kgEBFbBwr5I8bGOqgyHYzlAQrJF6FPp7xYlsQdhd3JYxX zDSbTGIo/NrWJobEwbuasMOiXxWNNyD18iBi87z8wOTHAOYLZGQkA4UDlBlVjfjZN4OJAu+oONY gPT+TbDPPvLj+tHytHUgQtoaGKiiDPg== X-Received: by 2002:a7b:cb97:0:b0:3f4:2c71:b9ad with SMTP id m23-20020a7bcb97000000b003f42c71b9admr9342533wmi.30.1683886778002; Fri, 12 May 2023 03:19:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4I9FrgEFsP//1tYj45frBjXyGRPhGYUW5a1OV52EDQ8S4OQvbRUweJYM7n/5XRKiIHRahXoQ== X-Received: by 2002:a7b:cb97:0:b0:3f4:2c71:b9ad with SMTP id m23-20020a7bcb97000000b003f42c71b9admr9342515wmi.30.1683886777707; Fri, 12 May 2023 03:19:37 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id k14-20020a7bc40e000000b003f4272c2d0csm13397003wmi.36.2023.05.12.03.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 03:19:37 -0700 (PDT) From: Andrew Burgess To: Simon Marchi , Simon Marchi via Gdb-patches Cc: Simon Marchi Subject: Re: [PATCH] gdb: fix use-after-free in check_longjmp_breakpoint_for_call_dummy In-Reply-To: References: <20230508145913.29359-1-simon.marchi@efficios.com> <87h6sk7doe.fsf@redhat.com> Date: Fri, 12 May 2023 11:19:35 +0100 Message-ID: <87v8gx6edk.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Simon Marchi writes: > On 5/10/23 05:12, Andrew Burgess via Gdb-patches wrote: >>> @@ -7608,9 +7609,13 @@ set_longjmp_breakpoint_for_call_dummy (void) >>> void >>> check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) >>> { >>> - for (struct breakpoint *b : all_breakpoints_safe ()) >>> + /* We would need to delete breakpoints other than the current one while >>> + iterating, so all_breakpoints_safe is not sufficient to make that safe. >>> + Save all breakpoints to delete in that set and delete them at the end. */ >>> + std::unordered_set to_delete; >> >> Hi, >> >> For my own education: why did you choose a std::unordered_set here? I >> would assume that we will never find the same related breakpoint more >> than once. Indeed, if we did then I suspect the old code would have >> resulted in a double free. >> >> So why choose a set over a vector? > > We look for bp_longjmp_call_dummy breakpoints, which are documented like > this: > > /* Breakpoint placed to the same location(s) like bp_longjmp but used to > protect against stale DUMMY_FRAME. Multiple bp_longjmp_call_dummy and > one bp_call_dummy are chained together by related_breakpoint for each > DUMMY_FRAME. */ > > I can imagine this happening: suppose X and Y are two related > bp_longjmp_call_dummy breakpoints, following each other in > breakpoint_chain. When looking at X, we will insert X and Y in > to_delete. We will then look at X, and we will try to insert X and Y > again in to_delete. > > The old code wouldn't double free or use-after-free, because of its > special handling of B_TMP. When looking at X, we would delete Y and > then X. And if Y happened to be the next iteration value (saved in the > B_TMP variable), we would modify B_TMP to avoid iterating on Y. Thanks for the explanation. Andrew