From nobody Tue Sep 16 02:29:46 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5754EC54EBD for ; Mon, 9 Jan 2023 07:55:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234227AbjAIHze (ORCPT ); Mon, 9 Jan 2023 02:55:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236181AbjAIHzZ (ORCPT ); Mon, 9 Jan 2023 02:55:25 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D128913DE9 for ; Sun, 8 Jan 2023 23:55:15 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 3097sos7026016; Mon, 9 Jan 2023 08:54:50 +0100 From: Willy Tarreau To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Warner Losh , Willy Tarreau Subject: [PATCH 2/6] tools/nolibc: Fix S_ISxxx macros Date: Mon, 9 Jan 2023 08:54:38 +0100 Message-Id: <20230109075442.25963-3-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20230109075442.25963-1-w@1wt.eu> References: <20230109075442.25963-1-w@1wt.eu> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Warner Losh The mode field has the type encoded as an value in a field, not as a bit mask. Mask the mode with S_IFMT instead of each type to test. Otherwise, false positives are possible: eg S_ISDIR will return true for block devices because S_IFDIR =3D 0040000 and S_IFBLK =3D 0060000 since mode is masked with S_IFDIR instead of S_IFMT. These macros now match the similar definitions in tools/include/uapi/linux/stat.h. Signed-off-by: Warner Losh Signed-off-by: Willy Tarreau --- tools/include/nolibc/types.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h index 300e0ff1cd58..f1d64fca7cf0 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -26,13 +26,13 @@ #define S_IFSOCK 0140000 #define S_IFMT 0170000 =20 -#define S_ISDIR(mode) (((mode) & S_IFDIR) =3D=3D S_IFDIR) -#define S_ISCHR(mode) (((mode) & S_IFCHR) =3D=3D S_IFCHR) -#define S_ISBLK(mode) (((mode) & S_IFBLK) =3D=3D S_IFBLK) -#define S_ISREG(mode) (((mode) & S_IFREG) =3D=3D S_IFREG) -#define S_ISFIFO(mode) (((mode) & S_IFIFO) =3D=3D S_IFIFO) -#define S_ISLNK(mode) (((mode) & S_IFLNK) =3D=3D S_IFLNK) -#define S_ISSOCK(mode) (((mode) & S_IFSOCK) =3D=3D S_IFSOCK) +#define S_ISDIR(mode) (((mode) & S_IFMT) =3D=3D S_IFDIR) +#define S_ISCHR(mode) (((mode) & S_IFMT) =3D=3D S_IFCHR) +#define S_ISBLK(mode) (((mode) & S_IFMT) =3D=3D S_IFBLK) +#define S_ISREG(mode) (((mode) & S_IFMT) =3D=3D S_IFREG) +#define S_ISFIFO(mode) (((mode) & S_IFMT) =3D=3D S_IFIFO) +#define S_ISLNK(mode) (((mode) & S_IFMT) =3D=3D S_IFLNK) +#define S_ISSOCK(mode) (((mode) & S_IFMT) =3D=3D S_IFSOCK) =20 /* dirent types */ #define DT_UNKNOWN 0x0 --=20 2.35.3