From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 289AC19CC08 for ; Wed, 8 Jan 2025 03:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736305202; cv=none; b=lwbH3oGCFWM/Drn/XCz5w0QAUsOaN0ZODsYNDJF9GboA6jlQRBdbSWhA1AIgQxc2hWzi4I+cvFUbdgx2di4D8l+q4ylhSuQNKnmV9tsPCKBKSLTl15yNnrNHnOt5mqh/SzwvQvLy+sZhEVQKAp2YYL2PIiR7v1PK/GK7MGgRv8c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736305202; c=relaxed/simple; bh=OATGo8aQcNYDw+H5AEmX2rtqICBX8uTSu1nPaZDpsng=; h=Date:Message-ID:MIME-Version:Content-Type:From:To:Cc:Subject: References:In-Reply-To; b=jATVetBUUftRRvHuIayRDycwqnwdzW4TphxSzosy5Uqkc31V1HMo4XUFxFp+OpqK97F43lDNoRtH7Vxv9LcPzqylzkBVjFHA+yvFJzLdw2gI1sZICL1fb8n5aGfkdMhUzciGOK166I/vBaxK/utKzbTTkV9QXPEE10sdwYV9qLo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com; spf=pass smtp.mailfrom=paul-moore.com; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.b=N8N7u72Z; arc=none smtp.client-ip=209.85.160.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paul-moore.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.b="N8N7u72Z" Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-46785fbb949so148825891cf.3 for ; Tue, 07 Jan 2025 19:00:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1736305200; x=1736910000; darn=vger.kernel.org; h=in-reply-to:references:subject:cc:to:from:content-transfer-encoding :mime-version:message-id:date:from:to:cc:subject:date:message-id :reply-to; bh=mDJSexMwGrVR6YaQuKuB48uyMoRezKWjJmWZhA1XR24=; b=N8N7u72ZTjLjtqTAixMc4Hh7ICuUHlPws23AUYi7Kzy2tCm+YnJ8e2FWBYDmEgWGKy E6cc2U1Dw+Uq2o6zzLy9YXDZ+ANVPecovaD/F530DP/7ExkYI3/xgZ+QaEGpPFHIn5eM FqN09wIRFnvHwM4SPZj4XuDTpkh+a+0zqs7ZkIIonjeAfI9HvGHd7IUcmRPsml2sU5Ez Yc/M8/mruws6E0yIWsaXX9cnvLqCeY0IbhTmUFZwRYmsPtTL+zyQveYiWDHVRVamrSfB 3UfrWwzoQHGPPysVfcGK1QWP6h7VCfs8E+Kd0NNJMku+9OuWPj36uhdE73WTBCU0nWu3 9+4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736305200; x=1736910000; h=in-reply-to:references:subject:cc:to:from:content-transfer-encoding :mime-version:message-id:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=mDJSexMwGrVR6YaQuKuB48uyMoRezKWjJmWZhA1XR24=; b=b0FO+6kFzLJCsP8vMFI1fAv+8yOKUSTNARitM8pJh98pXD24TwA3M7OycT+ZzvL0TL rHhWPqiI6r7v0QsUK7zaxF0JAkoq3Ijvs1Ep635Lr2x6OfGwIkAm0mVBAssN2EN7EdWh 3aPUFaI7gUt8Kq9i8E0IAcID8uua+ja36O7T96mM4VwawzJrk4C/sgAt2DTMLH/iWZ+i VBAimns37g7eXG0iV78a4dNQkkA+W9JID+CqdwWr2uMazirDphGegrP9+cfwbicVrkix mCfTrXmsyu3UGrSWs/v8C4seCaqNH+CYMgi7QVeRYLUiZ+l6tbdUqyjC3OeYu2B4Mvw1 63XA== X-Forwarded-Encrypted: i=1; AJvYcCU/OTOh8M7iJD9hxMZOreL6AE6E/Hrzy+8ntEEJ+O8H0+2bgekOahd6ahk1geb64uO6WXEbPhKeaeoqI0Y=@vger.kernel.org X-Gm-Message-State: AOJu0YzOWzp53F7wBu8tavTdhby0CkgUbsAt0JIRVEy3thdfdPbXktI5 7ESEoBji/XkfhzTCzgd6YaQqAyQPosRzdoKewwkq9nuYx2IMPJ0xN1N002adEA== X-Gm-Gg: ASbGncvo1A/dhWVQDWCHORWFTXOqztej9brxi0fe2auhGBmH3DViPnLEug9yu1dZqbO lHwqDe5iBxdkGcGNk3+as2LWHPbFFj4r+gVA9DHGd0nhX9+O1zvuPbFXNRj188jdQcF7xo36Pg3 S7Xw9XLIxW4Ze7oWYMLtm/rKIQ4+QQQl8sAPGB7fLNxvZYgOPxIkDNjE8SFtgMiTFG90JtzbXDX MixIaykQ8RT6fq9eWAr43u+xtLC5hYJLy3YjfOSf/eugIA4c8M= X-Google-Smtp-Source: AGHT+IEvu01NUR0GRR179mj45ii+bvHS1vbr47fBw9MkS6Z//pM+fOXYZIIfnSnV6RMGYeOm49gVMQ== X-Received: by 2002:ac8:58cf:0:b0:460:8f80:909a with SMTP id d75a77b69052e-46c710314ccmr23177491cf.32.1736305200113; Tue, 07 Jan 2025 19:00:00 -0800 (PST) Received: from localhost ([70.22.175.108]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46a3e653893sm191974381cf.1.2025.01.07.18.59.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 18:59:59 -0800 (PST) Date: Tue, 07 Jan 2025 21:59:59 -0500 Message-ID: <01df64ed8f6eb9e6f2780b5b0aa3be5c@paul-moore.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailer: pstg-pwork:20250107_1610/pstg-lib:20250107_1603/pstg-pwork:20250107_1610 From: Paul Moore To: =?UTF-8?q?Christian=20G=C3=B6ttsche?= , selinux@vger.kernel.org Cc: =?UTF-8?q?Christian=20G=C3=B6ttsche?= , Stephen Smalley , Ondrej Mosnacek , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , =?UTF-8?q?Thi=C3=A9baud=20Weksteen?= , =?UTF-8?q?Bram=20Bonn=C3=A9?= , Masahiro Yamada , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH RFC v2 5/22] selinux: avoid nontransitive comparison References: <20241216164055.96267-5-cgoettsche@seltendoof.de> In-Reply-To: <20241216164055.96267-5-cgoettsche@seltendoof.de> On Dec 16, 2024 =?UTF-8?q?Christian=20G=C3=B6ttsche?= wrote: > > Avoid using nontransitive comparison to prevent unexpected sorting > results due to (well-defined) overflows. > See https://www.qualys.com/2024/01/30/qsort.txt for a related issue in > glibc's qsort(3). > > Signed-off-by: Christian Göttsche > --- > security/selinux/ss/policydb.c | 18 ++++++++++-------- > 1 file changed, 10 insertions(+), 8 deletions(-) > > diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c > index 3ba5506a3fff..eb944582d7a6 100644 > --- a/security/selinux/ss/policydb.c > +++ b/security/selinux/ss/policydb.c > @@ -37,6 +37,8 @@ > #include "mls.h" > #include "services.h" > > +#define spaceship_cmp(a, b) (((a) > (b)) - ((a) < (b))) I'll admit that it took me a while to figure out why you decided to name this macro "spaceship_cmp", and then I had a little laugh when I realized why it was called the "spaceship" operator :) Anyway, while the spaceship operator is likely familiar to people who have a Perl background, the kernel is still mostly a C project so I don't think we can expect a base understanding of Perl, especially these days as Perl isn't as popular as in the past. Can we rename this to something else that makes more sense in the context of C? -- paul-moore.com