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 1rXuaX-00DG0o-Io for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Feb 2024 02:56:34 +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 1rXuaV-00EZbi-V4 for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Feb 2024 02:56:31 +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 1rXuaV-00EZba-MA for pgsql-hackers@lists.postgresql.org; Thu, 08 Feb 2024 02:56:31 +0000 Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rXuaO-0063G5-Hg for pgsql-hackers@lists.postgresql.org; Thu, 08 Feb 2024 02:56:31 +0000 Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-7beda2e6794so17995539f.1 for ; Wed, 07 Feb 2024 18:56:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707360982; x=1707965782; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=4T6b2FnpncIZSXRAk9IYWQvbHWjKooTE+ftO3Brt5Tk=; b=gmkcQS8bcIgSKxgMZuGvBCtyOkK/4x26sEf2IU4FOxtBpTF0H3qzqOkYNMN9TiU7XJ yK5N4ODQrN9pyD8sKpa/mhGb2c1MiO7/FKc5nn0M3dYElr3TWjMuB20bnxq8zeTAQlo9 dWHx5sJ0D30H8NoPiRJ8/cBRkaKuDZRJeWidk1HUBIbzkr7btA551h63fYjn/0rFTtBf uknKkzzkiEHNjCw9Zcsh8rBXhhBijL16vLVzSeNYvgMRDkj8p9tEUjmISONSMQQzpiaA OrCHVLn9sFIE2kN27O8jflSK2I9vS5bcjvIEq52m9bUI2tfACqRoh9pBSbR3L4a/0aoq CPYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707360982; x=1707965782; h=in-reply-to:content-transfer-encoding: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=4T6b2FnpncIZSXRAk9IYWQvbHWjKooTE+ftO3Brt5Tk=; b=BOeAvKu7qM4Qo4x5dm82Fm71jsLjqoapwznlqA1iVpnVh976upXDxwijqfjmYfCePf FvpLptyaQeJuJ9kbM3dZXnz6vTb2coFYv1yZJVtRpDmRfvmYS31Y7EwvILI9MOMMVKfp aKjOUXbjfZ9wB051ayRNyj8kfPXe6NSyYbmwQF1Sga00fjs3nuJAlJFAmDoW8WTJ27iI Dxczau1HeY1RGdsJB19XRh2LUmESe9YINWLla1uc7bR7ASbRUyHvO+K9eMsyU7PZTwD9 L/0mtjEhl4Wb+KPxIDAmIveGREsN7q/1L+WtFMDMboQX1+hHzO++VwrV04HUO1RlgwSE kKaw== X-Gm-Message-State: AOJu0Yye8e5TxtujJLKYNA/g0rZScH3rIpA/QKVnUuCkLhE+sN5ht9xM bzUq6dgGxaZ+zOAfaWXHtntRpTtGSEBnE/sPxFC35b5iHL7qP7aD X-Google-Smtp-Source: AGHT+IG8YnyNkevh1/Pxvs3XiaIUR/v3+0qA9CDynp5ysd+6/S8qAg8LrH70wCilgQjBfCsrjGZTAw== X-Received: by 2002:a5e:aa0b:0:b0:7c3:f542:66cf with SMTP id s11-20020a5eaa0b000000b007c3f54266cfmr1167191ioe.0.1707360982380; Wed, 07 Feb 2024 18:56:22 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXTBtVFT86BRp6YpVit9qAXL2Ovo4E4jYrHVG3DazCbsMlQ1jWaGS3QDJOtU5QMLuxZqROmlf8uYQ0AxTGenAVPbSR6jT3F9kUB50pJPsjTz6cyESTIGB63zEUVNI3rMayosgOkA0vD2vJCM5HdbpKyvBnrnLvNno76hw2GDagRr5QkAPwpWnQhxGk= Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id q10-20020a0566022f0a00b007c3ff9c1259sm627000iow.0.2024.02.07.18.56.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 18:56:22 -0800 (PST) Date: Wed, 7 Feb 2024 20:56:20 -0600 From: Nathan Bossart To: Thomas Munro Cc: Andres Freund , Heikki Linnakangas , Mats Kindahl , Tom Lane , pgsql-hackers@lists.postgresql.org Subject: Re: glibc qsort() vulnerability Message-ID: <20240208025620.GC445153@nathanxps13> References: <642084.1707252958@sss.pgh.pa.us> <20240207214857.rjqkutiaapka2xyp@awork3.anarazel.de> <20240207222124.GA382832@nathanxps13> <20240208004207.aoyrtv577nmhrivy@awork3.anarazel.de> <20240208015211.GA445153@nathanxps13> <20240208020637.3irwi5vph4fbxw2f@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Feb 08, 2024 at 03:49:03PM +1300, Thomas Munro wrote: > On Thu, Feb 8, 2024 at 3:38 PM Thomas Munro wrote: >> Perhaps you could wrap it in a branch-free sign() function so you get >> a narrow answer? >> >> https://stackoverflow.com/questions/14579920/fast-sign-of-integer-in-c > > Ah, strike that, it is much like the suggested (a > b) - (a < b) but > with extra steps... Yeah, https://godbolt.org/ indicates that the sign approach compiles to movsx rsi, esi movsx rdi, edi xor eax, eax sub rdi, rsi test rdi, rdi setg al shr rdi, 63 sub eax, edi ret while the approach Andres suggested compiles to xor eax, eax cmp edi, esi setl dl setg al movzx edx, dl sub eax, edx ret -- Nathan Bossart Amazon Web Services: https://aws.amazon.com