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 1rXqIP-00CvsM-EZ for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Feb 2024 22:21:33 +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 1rXqIO-00Dfmv-0y for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Feb 2024 22:21:32 +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 1rXqIN-00Dfmn-Nk for pgsql-hackers@lists.postgresql.org; Wed, 07 Feb 2024 22:21:31 +0000 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rXqIK-0061Fb-VN for pgsql-hackers@lists.postgresql.org; Wed, 07 Feb 2024 22:21:31 +0000 Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-7bf7e37dc60so61968039f.3 for ; Wed, 07 Feb 2024 14:21:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707344487; x=1707949287; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=V4E3cdV3dZsAPrNo7GmIYnL2FRI+sKw/IwQhpYo86Us=; b=mOxSCTYTItSZCSCEnnaS3TbJv+wHgfzzEkrPVdKhWyTDVSBfyMPuzA8HXIsJRIYJNf EFSHs0JfRMzaLJl3WEenfTxInR4qkYMX4ZNUL5tvRfM06nPx91Fv670eEMT3ZaN3M4v8 ytdu0zqdRIKlaUiuJcfvXkkStcMAlw+1/k0+TI/wSr1rRn9+M7O6ltRHeb5h5Pdcl31p shQb9bGIn5kwB/JZxBTHJjIWisEurnqz0WuMR3HwLYcHgK43j8Ns02/TcNlM0Mfx2mod FiPj5yciy+Z+MvYhlIURy28uLXMZNWmNPPFaJlhkSPvaaLZLDQMZZfHg1F7zwocvtEdc ITnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707344487; x=1707949287; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=V4E3cdV3dZsAPrNo7GmIYnL2FRI+sKw/IwQhpYo86Us=; b=igPsWQ7JH6Aqmf8LQCWBY19loFaCJjDJyMBdP7EG9vIhYfbt1LsdQpnyPaw/1olkhG wqdjJgQfHx2K+ORLXez7i0Ymxqt/XHreuySQ2zGdYii/LezD3kW7mfBqwKiOGe6fProh RRhFgJ0ut7NYfgtoXzgTMRsXoM4/+AL6P5WLjwRhlOQoXHnoIVDqU0Thec5xGrSoAsih mpSg/qPRyy+CqA9MjrRr989WuJXe4PtLNJL94XUVnDqS4ei+o4FEXQ9trP7gMh5wvN/w cvs54YcRXN7J6EXrulIzNoktgwPXkFzcssD1KVCbolsC4NM0IvYhWeqGpUTHU5COuSG5 Ro7A== X-Forwarded-Encrypted: i=1; AJvYcCUwcA5CsQWdX6DcxyUA1sYEQ1UaMdoXx1y+T4NsDL55aI3MZ2e51wucSpRRNiaqeZjmLeRN26eJePhVNZTuHN2daV3FlkJt1lFVet1UrXuZi09s X-Gm-Message-State: AOJu0Yyn0EpMVO/218+xGMTFvMbBXrgh4CdvVjgqXWvIi7NTZAbGzEmv 4kGzLtcWjwDt48W+OGiHucFL/c9CJn1tiKt9GRb3f+AvpJCQhDy5 X-Google-Smtp-Source: AGHT+IFnVID3A4qaHBDSq7Sn9kgy6cH4n8nsPnDsJ6Oj2lrAKVxjNAcdEzAsy+iYw9Fg3B/ON0M1hQ== X-Received: by 2002:a6b:5808:0:b0:7c3:f4f3:f47b with SMTP id m8-20020a6b5808000000b007c3f4f3f47bmr6038202iob.7.1707344486837; Wed, 07 Feb 2024 14:21:26 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUL8jYUNtJvpiAiLXe+YEVnFZUiofZNtKeadTWM7m+KGoKXB+b3bdyDulAnIOWud1JhTp9Kg+vTGtpRfUEvNYqUv4Y0yQQnuahmelb5YvoX7L4/FTWLqraBkZvynwKRXKpy+EUevqByFlcEjfhXqhCWXng66BuUErtt Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id t5-20020a02c485000000b0046f323505f8sm543737jam.170.2024.02.07.14.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 14:21:26 -0800 (PST) Date: Wed, 7 Feb 2024 16:21:24 -0600 From: Nathan Bossart To: Andres Freund Cc: Heikki Linnakangas , Mats Kindahl , Tom Lane , pgsql-hackers@lists.postgresql.org Subject: Re: glibc qsort() vulnerability Message-ID: <20240207222124.GA382832@nathanxps13> References: <508821.1707232276@sss.pgh.pa.us> <20240206205305.GB3891538@nathanxps13> <642084.1707252958@sss.pgh.pa.us> <20240207214857.rjqkutiaapka2xyp@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240207214857.rjqkutiaapka2xyp@awork3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Feb 07, 2024 at 01:48:57PM -0800, Andres Freund wrote: > Now, in most cases this won't matter, the sorting isn't performance > critical. But I don't think it's a good idea to standardize on a generally > slower pattern. > > Not that that's a good test, but I did quickly benchmark [1] this with > intarray. There's about a 10% difference in performance between using the > existing compASC() and one using > return (int64) *(const int32 *) a - (int64) *(const int32 *) b; > > > Perhaps we could have a central helper for this somewhere? Maybe said helper could use __builtin_sub_overflow() and fall back to the slow "if" version only if absolutely necessary. The assembly for that looks encouraging, but I still need to actually test it... -- Nathan Bossart Amazon Web Services: https://aws.amazon.com