From patchwork Tue Feb 15 23:10:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 51145 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B6354385843E for ; Tue, 15 Feb 2022 23:11:11 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hall.aurel32.net (hall.aurel32.net [IPv6:2001:bc8:30d7:100::1]) by sourceware.org (Postfix) with ESMTPS id B5E153858C83 for ; Tue, 15 Feb 2022 23:10:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B5E153858C83 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=aurel32.net Authentication-Results: sourceware.org; spf=none smtp.mailfrom=aurel32.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=aurel32.net ; s=202004.hall; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From:Content-Type:From:Reply-To:Subject:Content-ID: Content-Description:In-Reply-To:References:X-Debbugs-Cc; bh=bs0ONrhSrocPJ0yhoy8JHzgjhBOxfCgEsKTV1Vrr1ys=; b=w4rMKedxM3lvgjYp/kDdK3w9Mo /QXsESJPM9xUB+lCM0hXWR1fnT4ERQ98TwnsOWjnXHz4gZjgFdddjwPIMFqFypQeOQSu0YbfILckH bNXgA/ZHBjHpPT5sOqNHlbKUCn1JQleLl1XnV4FXAQFCp+A7E99EYSelKa0Ec386tK0VRQGx01VCW hC7OSTMIgZQ9z/3WUmLXZXl/8GY1/ss8D/jgy+Y/alm28jcXDuGyyNX1mJSEXVAyll2BmFGlWwUrb AryhtkvJBq3C5e3X2xdNJmz/u8FhwvAjX9D1exAzLd6HCYcmKFEeIgTR2Z36cHp/4QoJOJQJ9m4SF l7IiGBZw==; Received: from [2a01:e34:ec5d:a741:8a4c:7c4e:dc4c:1787] (helo=ohm.rr44.fr) by hall.aurel32.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nK6yH-00DpHj-BP; Wed, 16 Feb 2022 00:10:57 +0100 Received: from aurel32 by ohm.rr44.fr with local (Exim 4.95) (envelope-from ) id 1nK6yG-00EAp0-S5; Wed, 16 Feb 2022 00:10:56 +0100 From: Aurelien Jarno To: libc-alpha@sourceware.org Subject: [PATCH] _dl_discover_osversion: clamp parts to 255 Date: Wed, 16 Feb 2022 00:10:52 +0100 Message-Id: <20220215231052.3378121-1-aurelien@aurel32.net> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aurelien Jarno Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Some stable Linux kernels have a lowest version part greater than 255, and _dl_discover_osversion returns the wrong version for them as it uses only 8 bits per part (just like LINUX_VERSION_CODE). For instance kernel version 4.4.268 is reported as 0x4050c, ie 4.5.12. Kernel version 4.14.266 is reported as 4.15.10. The 4.9 and 4.19 branches are not affected at this stage as the lower bit of the second part is already set. Fix that by clamping the parts to 255. This is fine given that the GNU libc requires at least a kernel in version 3.2, and since kernel version 3.x.y the third part is not meaningful anymore from the GNU libc point of view. --- sysdeps/unix/sysv/linux/dl-sysdep.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sysdeps/unix/sysv/linux/dl-sysdep.c b/sysdeps/unix/sysv/linux/dl-sysdep.c index 8ad72c4b7b..1be3867226 100644 --- a/sysdeps/unix/sysv/linux/dl-sysdep.c +++ b/sysdeps/unix/sysv/linux/dl-sysdep.c @@ -379,6 +379,10 @@ _dl_discover_osversion (void) here += *cp++ - '0'; } + /* Clamp parts to 255 as they are later saved using 8 bits only. */ + if (here > 255) + here = 255; + ++parts; version <<= 8; version |= here;