Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ptKhs-0002rM-Qs for pgsql-bugs@arkaria.postgresql.org; Mon, 01 May 2023 04:00:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ptKhr-00065q-38 for pgsql-bugs@arkaria.postgresql.org; Mon, 01 May 2023 04:00:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ptKhq-00065h-Q0 for pgsql-bugs@lists.postgresql.org; Mon, 01 May 2023 04:00:06 +0000 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1ptKho-0065ho-06 for pgsql-bugs@lists.postgresql.org; Mon, 01 May 2023 04:00:06 +0000 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2a8b082d6feso20155771fa.2 for ; Sun, 30 Apr 2023 21:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682913602; x=1685505602; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=VRxl8ca9WBGs1oxkLrSoKt3AJidrLMQ/Xp3kxdDruMA=; b=Etj5qIGGc7fpN9vFcxAVY3HdiZRISBrKHChfWz3L34T73LOzArps6v29avgmPbt+5O 5WYgReZbqWnINwPzqqthak8plFl9TTA1hJF6/7Q92e3ZzwBcYPdG2wAq2sVVjyUv6rnd ZYwfkg+GKQF735vopYwwFNLQro3C9rqYPUKBHi1JRrw9QJ1FKDgvbYYpD8DTvW0rSOIS nOiJP5cdl3JSAZlQLyTXQo8pdeEsLkxzT7TPEFhfzNY4qKZr0wcN017NycsrJBMsyRkg qskR0Kwc/XLTZKgkvTJbevsXGRTfSZFnWBQbDDenwR+65j5ONR+te0Z/RWPndOvO+cUl R+Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682913602; x=1685505602; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VRxl8ca9WBGs1oxkLrSoKt3AJidrLMQ/Xp3kxdDruMA=; b=Z/d5r91NVLrrop2Ckt+zGhjmcM9up9/xi/+RATdOm0zGncr1VSWTsjI85FngsQJ/K5 pFrFwkjC+QtGISlznZA5HL5H20wIN6+EuqiTSBFvEntm2PtT2NhU4LZCbjXOnXcC9Znr cJlLQE2cEolHODuH/Ptt5fEKbzzbREz7Mzb3gbsEBB5x/JqSaz8cDkYHETGTqL5ZvwGg VAhqxFWVPq571xXp9KljAgxfkZTSaDJ4LiwQCtSJUtt9rmD2PycdhJ3MrkPxwJtcogp0 1WKXWYngGSykCJQSL420jeIHX7kroIS8vuZFq3jCadZO0hHBidICFTrW9Z6sI7nuPJIp 82bA== X-Gm-Message-State: AC+VfDzb6y/QOAPZggjOLv96tpXc1ZrBAEUYsyy6XLsl9buoNfTzDDVJ j/ZfsM7AamU6UnKaTP0ztkc= X-Google-Smtp-Source: ACHHUZ51vJJUwBFJsQ//jfIc7AgLzveLTIzz7kMP0/5ofjhTTgljaX7W1MVyDn0Lgn0sZnpbtG9LnQ== X-Received: by 2002:a2e:240a:0:b0:2a7:b1db:7f42 with SMTP id k10-20020a2e240a000000b002a7b1db7f42mr3223848ljk.49.1682913602341; Sun, 30 Apr 2023 21:00:02 -0700 (PDT) Received: from [1.0.0.7] ([178.155.28.115]) by smtp.gmail.com with ESMTPSA id p5-20020ac246c5000000b004eafabb4dc1sm4500977lfo.250.2023.04.30.21.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 30 Apr 2023 21:00:01 -0700 (PDT) Message-ID: <88b5750f-a5da-798b-e5a1-af2c3ecb9b60@gmail.com> Date: Mon, 1 May 2023 07:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: BUG #17798: Incorrect memory access occurs when using BEFORE ROW UPDATE trigger To: Peter Geoghegan Cc: Tom Lane , pgsql-bugs@lists.postgresql.org, Richard Guo , Andres Freund References: <17798-0907404928dcf0dd@postgresql.org> <87fe6c28-80b2-f709-a8db-d105e5240e39@gmail.com> <1849610.1682807087@sss.pgh.pa.us> From: Alexander Lakhin Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello Peter, 30.04.2023 23:39, Peter Geoghegan wrote: > On Sun, Apr 30, 2023 at 5:00 AM Alexander Lakhin wrote: >> Yeah, also the environment changed since 86dc90056, so I couldn't just revert >> that commit to test the ExecFilterJunk() behavior on master. >> >> All the questions you raised require a more thorough investigation. > Are you aware of the fact that Valgrind has custom instrumentation > that makes it directly capable of detecting access to no-longer-pinned > buffers? See commits 7b7ed046 and 1e0dfd16. Yes, I am. That's why I can't demonstrate real risks now — my repro triggers a Valgrind warning only, and no other consequences are visible. > I think that that may be a factor here. If it is, then it's a little > surprising that you ever found the problem with ASAN, since of course > we don't have custom ASAN instrumentation that tells ASAN things like > "until I say otherwise, it is not okay to read from this range of > memory, which is this backend's memory mapping for an individual > shared buffer that was just unpinned". The ASAN detected a consequence of the invalid memory read: ==1912964==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7f223dd52c78 at pc 0x55c9e846146a bp 0x7fff0c63e560 sp 0x7fff0c63dd30 WRITE of size 42205122 at 0x7f223dd52c78 thread T0 ... #10 0x000055c9e84d09c5 in fill_val (...) at heaptuple.c:270 ... Note the abnormal size 42205122 (the target table contained much shorter values at the moment). When exploring the coredump and the source code, I found that that invalid size was gotten as follows: ExecBRUpdateTriggers(): newtuple = ExecFetchSlotHeapTuple(newslot, true, &should_free_new); ExecFetchSlotHeapTuple(): slot->tts_ops->materialize(slot) tts_buffer_heap_materialize(): bslot->base.tuple = heap_form_tuple(...) heap_form_tuple(): data_len = heap_compute_data_size(tupleDescriptor, values, isnull); heap_compute_data_size(): here garbage data were read. So I'm going to start it over and find a repro that will show something interesting without Valgrind (and let estimate the probability of a problem in the field). Best regards, Alexander