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 1rY9IL-00EbNq-MJ for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Feb 2024 18:38:46 +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 1rY9IK-0024Sv-7A for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Feb 2024 18:38:44 +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 1rY9IJ-0024Sn-RW for pgsql-hackers@lists.postgresql.org; Thu, 08 Feb 2024 18:38:43 +0000 Received: from mail-il1-x131.google.com ([2607:f8b0:4864:20::131]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rY9IG-006AZR-VM for pgsql-hackers@lists.postgresql.org; Thu, 08 Feb 2024 18:38:43 +0000 Received: by mail-il1-x131.google.com with SMTP id e9e14a558f8ab-363b361ba6dso135975ab.3 for ; Thu, 08 Feb 2024 10:38:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707417519; x=1708022319; 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=JLZ3VffVjF83wLX/VMzFI+bF/OPJLh16KJxJaamSB7k=; b=F0j92NePFub3fIDWOIdUWiB/oulVg7hEGKhjLMLdfY8sgynwptVRSNuFKfJUKaTiVK x+zaRiMslCFAYI5hzD0FaU7wQ9DRQTXkq3EboodhEGyAJAYlU55VEVTwiNTDxrklOpJx lzHwrozHnGG12HjfZ1pqx4PrKY/qokEbUpU3rCwvuStdJFSGEHyMbwpWmZAarwvteS8/ ptjVFaDGPtcaw4m6eBSspsASICrKKJ0p/Zxy/grAASOgV+Vujxl4Mlp2ncLpx+PyS6KB cCKJDVRb0Ibuw4MuyPhg3c+/13b1Bs0Axq6XCT7hQxRCAUCRfP63sBGurYQhdXisw2TT C9hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707417519; x=1708022319; 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=JLZ3VffVjF83wLX/VMzFI+bF/OPJLh16KJxJaamSB7k=; b=QwbkI18NLqM3qTUC9+3u/+5wuU9S0Kb0NWaeer0lYUzLlPHkHgyOiYnMtix9AIjlWK dXLcMo4K06M04CoTEB66zDhpSEIkM0rOGSThEctxwBHR7sc4g5tsqsa7xCukxW7vUXiI ar1pNp+6R+WxhJKvkERfVWS9S3vJ2JE62E7sUpp6a9p/sO2xSS+ZEw60AqCuy6Q4R0Gz DSvdcZPuz0eTmoazHoEF0LW+Jh9tjokgSHtvFaDb4H3hsOMJ8MsZDiJiwGHKQQeJywfi y6zJ5ziJBUy+GkBvuXmKgw8JLQVKGr9E86EK0jQVF/bGIvrZQ3II++1PyCfwlccFnfn1 OlAQ== X-Forwarded-Encrypted: i=1; AJvYcCVgO3STHG8CEYx5VwMr26/+WTqbb30EPXn2ES0f4Wtp8THSRuLHjxhxN+WBH8mCMyh88FFZoVFWmJGnBmMDsySq/QCzbN+tHF5wAimemYGCcoug X-Gm-Message-State: AOJu0YzDrb7HCkHhuMywUyfFPg74wvhHQI4PSF0xT4FIsmYvjClG3l61 1n57nI/GmdRbNhFSukVHqKS1qCF/MDvttIye5YatzwiS6lIK3dBW X-Google-Smtp-Source: AGHT+IE8GflkIFGnFqvEa0EbF4bqjDDPn0SCB2WvM66wrXmlD7VdfUG7/tsGE1EBV0J00b7CwL5u7w== X-Received: by 2002:a05:6e02:d50:b0:363:d9fb:613f with SMTP id h16-20020a056e020d5000b00363d9fb613fmr465966ilj.19.1707417518891; Thu, 08 Feb 2024 10:38:38 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUiK21bK4xXnAQoPbZMreOQApybzHei3P5rRCIM9efPs8KNXA57KDBD0hnsba9HgKhwdI/tmz2M27rlkMj+q9dXBE8i42+RFGooDRBgqr/X0XXAKQy5dLQA3UuJPe1Q5F2aLirxSOCtGLDc5ncXRpkqZ0Lxomit1UVuvRWt+MunFwk+qKKFa0t12C4= Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id w14-20020a02cf8e000000b00471145b3f8esm993914jar.118.2024.02.08.10.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 10:38:38 -0800 (PST) Date: Thu, 8 Feb 2024 12:38:35 -0600 From: Nathan Bossart To: Mats Kindahl Cc: Thomas Munro , Andres Freund , Heikki Linnakangas , Tom Lane , pgsql-hackers@lists.postgresql.org Subject: Re: glibc qsort() vulnerability Message-ID: <20240208183835.GA503311@nathanxps13> References: <20240207214857.rjqkutiaapka2xyp@awork3.anarazel.de> <20240207222124.GA382832@nathanxps13> <20240208004207.aoyrtv577nmhrivy@awork3.anarazel.de> <20240208015211.GA445153@nathanxps13> <20240208020637.3irwi5vph4fbxw2f@awork3.anarazel.de> <20240208025620.GC445153@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 02:16:11PM +0100, Mats Kindahl wrote: > +/* > + * Compare two integers and return -1, 0, or 1 without risking overflow. > + * > + * This macro is used to avoid running into overflow issues because a simple > + * subtraction of the two values when implementing a cmp function for qsort(). > +*/ > +#define INT_CMP(lhs,rhs) (((lhs) > (rhs)) - ((lhs) < (rhs))) I think we should offer a few different macros, i.e., separate macros for int8, uint8, int16, uint16, int32, etc. For int16, we can do something faster like (int32) (lhs) - (int32) (rhs) but for int32, we need to do someting more like what's in the patch. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com