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 1rXtaQ-00DBct-An for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Feb 2024 01:52:22 +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 1rXtaN-00EFoU-Jw for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Feb 2024 01:52:19 +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 1rXtaN-00EFoM-AI for pgsql-hackers@lists.postgresql.org; Thu, 08 Feb 2024 01:52:19 +0000 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rXtaJ-0062p0-Ki for pgsql-hackers@lists.postgresql.org; Thu, 08 Feb 2024 01:52:18 +0000 Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-7bc32b0fdadso55443439f.2 for ; Wed, 07 Feb 2024 17:52:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707357133; x=1707961933; 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=ZO5W/A1CKRXfFSS6MHhlEKiLxhu0phs78Ho0sZBogx4=; b=VJjlMExyz8l4phPNvbzH4+vAJku0u/AwimL5YVVOuyibcgIF3unq1YRdtc2wEBvP/l Iyb1qX9/PR5QWo+ebQsDWdZI6KE7SLAhJBZsyfFLeiBhk+44Snl+s9SIIQEm6vWVRYUH fKIlP2Fkp3F3VR4ZXNj62gLZ2B4RB4ico2RjuEJhSnJmsKj8fDv5hYy2SNiohSKPOxyB PDgDW7VT2jGcDxF+ouWgf6krFWaGvY9DCliGguMYolwkS59YJjm3IWVFFTqUzXVIuDDV UJifFl2DONYBDKD/mWdZ5u/LnWxfifOPMqyBkpxa+dbOiXiT+pwDZwB2cwgMQTGQRJBJ JNAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707357133; x=1707961933; 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=ZO5W/A1CKRXfFSS6MHhlEKiLxhu0phs78Ho0sZBogx4=; b=s6PKR5+wKetmu/mjG56XWQ8dqaFpEDMMLGTuceoNJnsuLT8T+SlkGduesNwf3yWPFl K7zLIC78teDvi5hQUMhIMILuk4jDP5wyCQBFUKMehMJF/NAi6zkZ2xnYLBZksHeaYML8 ZC8W44q/a2+oLRamkkV8ik1ghBk4Et3LGP+XLv9pmjMGRmM0ioCxVoLr7uO4SJRMDU+z +9+fd0oI1fkfgoDrvNV0a7YAd8ut0Tt8FMmTq3jMBvO5BSNtROvQdvE+wwnLXOwzHWZT 0zhFjm5E1d2QARN7xFxyWBIMHFkaW/gqFdfCSOF9/a8zlFqUqLCRq4ySmMQl9CxC+7If jhtg== X-Forwarded-Encrypted: i=1; AJvYcCWqKA688DuJAqtnWT7kJQdtdMK0nk+R7w7Elv5wHulcIhXaD1xJ/iCnjU3m3lDBXVWzx2tZUiDcIWsFu10sOOHNdZZXiZ6xqtEGxB0ZLoMJ/rga X-Gm-Message-State: AOJu0YybiDMiyxtrXWJigbi9PFzCuTwBG/MJU92r8NmdtbUakHC/QwRL As48tG0xZeHK2A8qipT21PO0WcpH/zZ1NRK1VwG5fRHz+C8NuuyK X-Google-Smtp-Source: AGHT+IHYZaxkjuEYc5WVjPGTb18LPvO7NYiqgKYS0IyGBho1N1cdVovmZpSzdIj842paykjkbGMkNQ== X-Received: by 2002:a5e:8f4d:0:b0:7c3:f4ee:4709 with SMTP id x13-20020a5e8f4d000000b007c3f4ee4709mr6891023iop.13.1707357133625; Wed, 07 Feb 2024 17:52:13 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWgRka1RRvD3+/C+du8clc5gZUV+xwV16X4bNQtkWdx14FqgTa6NYy4rByJaOoIpwzwriCKMrjX3KijmZM8nLCThr8ofQY3ZdZfWDIjgnSN9dKKjFV3Hba4cFXk/GWIANRiXHluGLEQ3tNrlVClQi1yKn7tWI6AQTNx Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id fm12-20020a0566382b0c00b0046e917416c8sm645037jab.89.2024.02.07.17.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 17:52:13 -0800 (PST) Date: Wed, 7 Feb 2024 19:52:11 -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: <20240208015211.GA445153@nathanxps13> References: <508821.1707232276@sss.pgh.pa.us> <20240206205305.GB3891538@nathanxps13> <642084.1707252958@sss.pgh.pa.us> <20240207214857.rjqkutiaapka2xyp@awork3.anarazel.de> <20240207222124.GA382832@nathanxps13> <20240208004207.aoyrtv577nmhrivy@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240208004207.aoyrtv577nmhrivy@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 04:42:07PM -0800, Andres Freund wrote: > On 2024-02-07 16:21:24 -0600, Nathan Bossart wrote: >> The assembly for that looks encouraging, but I still need to actually test >> it... > > Possible. For 16bit upcasting to 32bit is clearly the best way. For 32 bit > that doesn't work, given the 32bit return, so we need something more. For the same compASC() test, I see an ~8.4% improvement with your int64 code and a ~3.4% improvement with this: int compASC(const void *a, const void *b) { int result; if (unlikely(pg_sub_s32_overflow(*(const int32 *) a, *(const int32 *) b, &result))) { if (*(const int32 *) a > *(const int32 *) b) return 1; if (*(const int32 *) a < *(const int32 *) b) return -1; return 0; } return result; } -- Nathan Bossart Amazon Web Services: https://aws.amazon.com