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 1mxBiT-0005yB-BN for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Dec 2021 17:35:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mxBiS-0006YO-7l for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Dec 2021 17:35:52 +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 <9erthalion6@gmail.com>) id 1mxBiR-0006Vp-VQ for pgsql-bugs@lists.postgresql.org; Tue, 14 Dec 2021 17:35:51 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1mxBiQ-0004Lk-37 for pgsql-bugs@lists.postgresql.org; Tue, 14 Dec 2021 17:35:51 +0000 Received: by mail-wr1-x42d.google.com with SMTP id o13so33617772wrs.12 for ; Tue, 14 Dec 2021 09:35:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=RyiQtOQ+mfVuBzpLEX7uWZchpcIP6odpYNDq9OIY/d4=; b=hHWofH23gJKRbs2ylW93WbjyXoS+/mGwuz8rAzxenJ2n+9syKPvvpnuLebSf8mi1Y1 EQJmaIChL8xiTJgi3R1u8KcJ8fCfCy29JppAnjOlBYBlsMoXXhdeQ1QHSzmQMw8TpuqA +5mg+XpaHGB2wCZz+zTKQwM9Af3yC1muPVpnZH7bHWXc1N8FlyNG7VuLrImBZd6sWa8D uF/V8wUri81E8tSfWj2pIbDdYcUtzWq59WSlLK4FvMZ8FrU9h+cQnKaynM4/vLeAFYr3 h9fdd7KHBaUyd9eX0PScG2TLLMmET6U+Touwb34zOyJdVEhsa92qoxwHQcWCGi6Tx/mF aGjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=RyiQtOQ+mfVuBzpLEX7uWZchpcIP6odpYNDq9OIY/d4=; b=DElVVg84rZqHSeDL4e12JUnPj0mYM6koQUB/MtlmAzOy0HWzyX2GWnQeypvnhfPvZ3 n0REpsUL0ZBEITP/bPKS5U4pPInnU5Q/CXUI9HLiYhZ81hCD5J7ZGJKBvVvvhYa2C4Nz J0YFjlnnsjkMldjAgi/mrRfKFV7mcSOWOxea2D1cFjiUowsa3S0w0S2aAYiQ2/BdxEUw yPDF8MXHqtA8H34blSf5SntiF67dYLvJaTrqJJ6YLmBLPmCi2/IWSTiN+aiIu1YKiNLz Kn4YhyWqvrp7aGNd5jJctgw0qeu7jpzSHZpoYL//dENAsDPwQ5JlsX4TBhLVM+hHchKL TVsQ== X-Gm-Message-State: AOAM5339XrrHyXX+1jnNNTLHmSQFewZqBagzpwutrP+hWifnUB0XDvqE 3Cj3yh7A3EvxXRs3rwisJFM= X-Google-Smtp-Source: ABdhPJwhuSxBieOzWuXwEPePb8BuVqj0Fs2NIgUBCDXcnXsX76ZNhBwfEWu4+QWpGlHw/iHdkd2q6g== X-Received: by 2002:a5d:456e:: with SMTP id a14mr463474wrc.256.1639503349326; Tue, 14 Dec 2021 09:35:49 -0800 (PST) Received: from localhost (dslb-178-012-041-031.178.012.pools.vodafone-ip.de. [178.12.41.31]) by smtp.gmail.com with ESMTPSA id d2sm398439wmb.31.2021.12.14.09.35.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Dec 2021 09:35:48 -0800 (PST) Date: Tue, 14 Dec 2021 18:36:54 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Michael Paquier Cc: "James Pang (chaolpan)" , "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #17326: Postgres crashed when pg_reload_conf() with ssl certificate parameters Message-ID: <20211214173654.i54n54e7v73dvflj@localhost> References: <17326-d40bbb1386b6c9c3@postgresql.org> <20211208134601.gauysdttc65aoeze@localhost> <20211210142231.fvldmwwy4fr477h2@localhost> <20211214154604.cfmv4kpo2inkt2pp@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211214154604.cfmv4kpo2inkt2pp@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Tue, Dec 14, 2021 at 04:46:04PM +0100, Dmitry Dolgov wrote: > > On Mon, Dec 13, 2021 at 08:10:57PM +0900, Michael Paquier wrote: > > On Mon, Dec 13, 2021 at 07:06:16AM +0000, James Pang (chaolpan) wrote: > > > Edit postgresql.conf to change ssl_certificate parameter , > > > > Do you mean ssl_cert_file here? Also, something that's not completely > > clear to me is if this is a problem with a vanilla PostgreSQL > > instance or if this is related to the pgaudit extension set_user, as > > it has been mentioned as one potential origin of the problem upthread, > > but you are not telling if this is the case here. So what do you have > > for shared_preload_libraries in this crash? > > > > > #9 0x00007ff49a78059c in ssl_cert_clear_certs () from /lib64/libssl.so.1.1 > > > #10 0x00007ff49a780645 in ssl_cert_free () from /lib64/libssl.so.1.1 > > > #11 0x00007ff49a78a25c in SSL_CTX_free () from /lib64/libssl.so.1.1 > > > #12 0x000000000068b6b8 in be_tls_init () > > > #13 0x00000000007271e1 in SIGHUP_handler () > > > > Why is secure_initialize() not showing up in this stack? That would > > be the caller of be_tls_init() in the SIGHUP handler. The version of > > OpenSSL you are linking your binaries to would be useful here. That > > would be a 1.1.0 or a 1.1.1, no? Any specific minor version letter? > > I think I can actually reproduce the issue. In my case the stack is > fine, it contains secure_initialize, and overall it looks like some sort > of memory corruption -- at least openssl gets segfault because it can't > access some memory address it tries to verify in asn1_primitive_free. > Not sure yet why, investigating. After a short investigation looks like it's set_user problem. The extension has duplicating set of parameters, where one is the actual set and another one is "deprecated options". If I have both sets set simultaneously in configuration (e.g. set_user.superuser_whitelist and set_user.superuser_allowlist), on sighup in set_config_option / PGC_STRING branch / makeDefault condition something weird happens after set_extra_field, and after this point ssl context memory seems to be corrupted. Right before that an assign_hook from set_user is invoked to do something around "deprecated" options, that's why it looks suspicious. As soon as no "deprecated" options left in the config the issue disappears.