Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uhhVe-002wdS-Mb for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Aug 2025 04:36:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uhhVd-005IW8-Ew for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Aug 2025 04:36:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uhhSW-005GCo-5S for pgsql-bugs@lists.postgresql.org; Fri, 01 Aug 2025 04:33:32 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uhhSU-0008XO-08 for pgsql-bugs@lists.postgresql.org; Fri, 01 Aug 2025 04:33:31 +0000 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-b3507b63c6fso475936a12.2 for ; Thu, 31 Jul 2025 21:33:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754022808; x=1754627608; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=570PEiTT9sEhZj2WjaDX5OyY2bMX/c+qADenjxM9v78=; b=fudXYhUeVklTK026zWCTyV2apIk6z/zkXoZDMdIMd62OR2V1ehD2SOZF5u6ia3D8zP epKmpHnpKufMyvTNMQaA9mXDY7CQEpr3nR8mSeGoT3s163oWMc+ghLMAYiWW/t5JaE+o 07icPDg6DSzWTFh1KklJXBhWKSLaYePZL2hYM0O4xrgFBWCta4o4U7Foh93zJ03g9dBe azostRQ4d/3DwLQYJYPk78yxYLgPlXo2M9WVO5GekBKI87l1CagggykzqB+eYtlOelAy wVpSDrQXX5Dr6xxBxKKSdEaRCvhd6cPn0zT+gLC3aovt9DZLqinrFyVLdObVrdDybMIW bFFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754022808; x=1754627608; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=570PEiTT9sEhZj2WjaDX5OyY2bMX/c+qADenjxM9v78=; b=GivvG/E4CE8nyCHDr2glKvXqq5L4k7heffWM0ppdt5YUJTxf8QnPnCEHhhdJ04k8mN iJNGJHgvflUmcwfsLk2pp5S9ajiPa8vpO7Zut3UwWr+Q9W2cUcyyheluVkYWzpxbeiJ1 34JBa7PQ6ZBX8mvFR59FUGu3Iy3i/47nKDgIlSbJ/t36MZuF6qFO5pv1lRL0v2eFQMue ZUszEJJAOdxHDk6vUihY37ullRnuKpkz5VXf/3un2fCLMrjMtMZGz611XrSoIRh/Re7/ QACSokUg7jQvBEW5uja9AwLA+tLaOvVtyE2ugh0LGpAujC+48dYRvvqUBS5Wck+0dVEf X4YA== X-Gm-Message-State: AOJu0YzJYRJvkn1K7T/qnqUIyLRxQEyNIeLxfjsX6V5zZoSw/iRtxN3P grsoCea8uasmsWggMaY2+frqQu44N4jPKkjsPYWjAvaUv0JspXXlUTUKsQoe0BgV5j+7B2/hf9i QKx7wk8TchrpvBBNpKMAe4odllU5P9Eo= X-Gm-Gg: ASbGncusX/r/L9AjVWIe49XuWg3C0oK6gsO5/MJJQWPtTlqMGuHjKnu3RY5a6d8Oxq0 wTt+Tlg2z22RYZbfKsV7Gsnm2ciLJQNVdIyMlBFScVnbIZTfHyfWNUfdP+medk8/gZrzjJe6mfH fF+MbpYtAWgYvH7eXFe7ZBU5vqTQGxSBNIyXYeFF8sYEcTdYV9Cm01pD+wHSqTJ4lDxMMds1Fm5 za91tzjBg== X-Google-Smtp-Source: AGHT+IFHYtzit+E4tF+C2QRZVD/uRVoZrrNhawiht+DO3bU5Tx+wrkW/dCjQrqrl0V7YgklfIA0hs3TUHzHA5U8H5yo= X-Received: by 2002:a17:90b:1ccc:b0:31e:d2a5:c099 with SMTP id 98e67ed59e1d1-31f5ea4a331mr13128148a91.30.1754022807686; Thu, 31 Jul 2025 21:33:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Fri, 1 Aug 2025 10:03:14 +0530 X-Gm-Features: Ac12FXwU3frsR_MlFITlHfsbCIGk30x1ML3vQkQ4IAnZJhQJc87LlC7Ol0PmLp8 Message-ID: Subject: Re: Use-after-free in reorderbuffer.c for INSERT ON CONFLICT To: Michael Paquier Cc: Postgres bugs , Masahiko Sawada , Ethan Mertz Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jul 31, 2025 at 12:14=E2=80=AFPM Michael Paquier wrote: > > Ethan Mertz (colleague, in CC) has found a bug in reorderbuffer.c when > processing a REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM change, based > on the data gathered from a customer issue. The bug is a > use-after-free, causing random crashes, that can be summarized like > that: ... > > A simple solution suggested by Ethan would be to use the "prev_lsn" > guessed from the change at the beginning of the loop, rather than the > problematic change->lsn. But that does not seem completely right to > me because we can switch to "specinsert" as the change to process, > hence wouldn't we want to call update_progress_txn() based on the LSN > of the actual change we are looking at? > We still won't be able to capture the latest LSN in case of REORDER_BUFFER_CHANGE_INTERNAL_SPEC_ABORT. IIRC, update_progress_txn is used to keep the client active so that when many changes are skipped, the client doesn't timeout. In this case, it seems okay to use prev_lsn as well. --=20 With Regards, Amit Kapila.