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 1rYTo4-00GCo0-5m for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Feb 2024 16:32:52 +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 1rYTo2-009wZD-P6 for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Feb 2024 16:32:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rYTo2-009wZ5-Fe for pgsql-hackers@lists.postgresql.org; Fri, 09 Feb 2024 16:32:50 +0000 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rYTnz-005ue1-W3 for pgsql-hackers@lists.postgresql.org; Fri, 09 Feb 2024 16:32:49 +0000 Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-7c3e4290f5fso43745539f.2 for ; Fri, 09 Feb 2024 08:32:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707496367; x=1708101167; 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=PxmD1l8vYuz8YvOS+aWUIMgoHjZTsTu7M9t0ZvwbzB8=; b=asyTniby6gsPhz74/prRbGPjZO4WR90pKNa5zlKXZXXZt3BRxa8VMHyV1X+Dsz/Oz+ zWxBXi6wLliF6f8smvc9Aws63ehCq8LoyOQjoITUaKhy/1U5i7q8mK4R8xQ6dv/xJnXS 9Y3a3KGfrIIrn6KXsaXnJ+ursFWJ8wiJ4tMxNmdHO04xQWz2D8b+SbCbJbdllc+9JAiq cu5M5lvU+EYQE8jlo6TfW9Pfd3degs37gurTUFT0Dzi4av1J0zONjQSHESaNpoEJeLL+ qxSkWk5BHPFiEleTmilQ49ZBod3/LgT5ylWBynx3CqMInVzR4sMa2zRkvY+4bltUCrwM wMqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707496367; x=1708101167; 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=PxmD1l8vYuz8YvOS+aWUIMgoHjZTsTu7M9t0ZvwbzB8=; b=iJPxkETOXqNQvGxhU4OEULHLx0V0rk2NmtOjotk6UCkl89uB5ofeBDnfc4AwLXlpx3 LyboUi8YbTBZIqNSshMEHGsAAS3kGoLW6D2zMBJu2BZbi+nW+/dZa07e3th9QpzDAtCY Z3Srfqz9/6A27yib0GOjjfJSShDHatZYJfn0R1Umqyy5+SSHJ5DQdBR/0Bn5/E1muUuh 2nKxJ74v7EkOXyXN6gba1q/hvXzhoIVEPvpBOW61F023d2gceewrcRwnwQUAHLJbPdjz vDGFeG/ytaUfWYpGV/CBjdsIlyLjyzmKZG8dxurQEG/m1Xr9CBe6fI0Y2e1vxuGXL3kz RC5w== X-Forwarded-Encrypted: i=1; AJvYcCW/1sMMc34N0Im/K724fweDnr3Vjfxy63Bp6/tH/+I1O4r3wSSZK4WXxClZzYY0gkVPQbz+g9Afj+LLHiA8wyYcLcRkxRw7FT2jiIPPI8k8NQsK X-Gm-Message-State: AOJu0YzpfrcQzEByoM9u1m23kfo/qXfjJi2XkFvfHYghtMJBY3Dss3HQ 6vmTeOhZ3HkwM06rRPFxyBJRfeQZS7p+ZhqH+oH55nErFQO6QSgQ X-Google-Smtp-Source: AGHT+IFvozwd/XSDHRswgJSeQdWmtp3v//fMRWV/yIVvCnW+45wpPLkZTU8Ocy7+FugEIxOrJqPq5w== X-Received: by 2002:a6b:c80b:0:b0:7c4:8b4:ef6e with SMTP id y11-20020a6bc80b000000b007c408b4ef6emr2715628iof.14.1707496367219; Fri, 09 Feb 2024 08:32:47 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCX1avmgQF+kPo8j3csmcPUBk89gN7RVZDrc/esv4xofpAoPRzgswbzup3Wrp0XuQyHGwbLeSNwqX8BRnOdc/rhpsBUI0hU4wB6TMrKXROEzHG1sXKHdZHqkj/lDXaGWPoQgT9f4C3xV1jjyGn47Pq4UhALS8ZLCg7zUCYvlvfMznAhEaBi2MO8Z9m8= Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id f10-20020a02caca000000b0046e8d86f2a7sm478207jap.57.2024.02.09.08.32.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 08:32:46 -0800 (PST) Date: Fri, 9 Feb 2024 10:32:45 -0600 From: Nathan Bossart To: "Andrey M. Borodin" Cc: Andres Freund , Heikki Linnakangas , Mats Kindahl , Tom Lane , pgsql-hackers@lists.postgresql.org Subject: Re: glibc qsort() vulnerability Message-ID: <20240209163245.GB663211@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> <20240208015211.GA445153@nathanxps13> 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 Fri, Feb 09, 2024 at 01:19:49PM +0500, Andrey M. Borodin wrote: > If we care about branch prediction in comparison function, maybe we could > produce sorting that inlines comparator, thus eliminating function call > to comparator? We convert comparison logic to int, to extract comparison > back then. > > I bet “call" is more expensive than “if". It might make sense to have a couple of built-in qsort implementations for pointers to integers, pointers to unsigned integers, etc. However, a lot of current use-cases require inspecting specific fields of structs, so (assuming I understand your proposal correctly), we'd end up with many qsort implementations. If that can be made simple and elegant and demonstrates substantial improvements, then it might be worth considering, but I'm somewhat skeptical that the current uses are performance-sensitive enough to be worth the effort. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com