Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1799600pxa; Thu, 6 Aug 2020 16:42:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlvC7nYsB9HGafJw+/2M2wAIINoEmPKHhvYcjNKk679ftYbGfxOiIgMrE6f3Rt95smIsEZ X-Received: by 2002:a50:8f44:: with SMTP id 62mr5354833edy.351.1596757324955; Thu, 06 Aug 2020 16:42:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596757324; cv=none; d=google.com; s=arc-20160816; b=zZc+RMIpJYiF52IgbCEcLkKw925t3fMnugw3PkyVBHFCfkM1pM/9HnzGc5AYhrbk2i +hJuFrxQ4ciZoPkNRHK+Uw4NtLf9ma3948C42lbBgyEreke5JeRX64A8epYHcfq49T7r 2fIISH/8Xv55DJJiUiyWKIqzlYJnWiPDdQUELaB3+75qZhqEw4Xg7wUhdsP2R2KcwSVN VssNjIv+cWQACbhiQUuYrC5PYL4KZDUcIyDGRXs0FmCF5VWNupuhbI1SocrvGNGhAwgK R+wROzm8ftVhidnV1uu/1XCP/3JZ3EpwpQZNZdI7cxXpjxLcTAzNAUWPMfN5bedLYiAY tZ6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:dkim-signature :dkim-signature:date; bh=P4nbLAAuSFU/iG/0iov28OXKQeCl8AQVN5QtOnyn6SA=; b=VNcRI3t/GGALo63rbYIFTlv+QSWAtwox9mxkPyimr58WaLFyzdCxVWdDXtvmogyDeT uSSWWN3qUuJmXsjU++BnmQitxgz2z/Raj/nIg6JQNat+Gw/8bTPUoEEyXiBPdSuSBgTK WJLdASWPKz+bjjpthWciI6AFUIcpL3DI5u417JbZmy8VqgCsALzseOttAlg7uFIOOr6M RnjvQEBho7dq38ElMc22CirAhKcXWH8dftuaFcaMdqIbJKeohAyZHagkLqfPKLcMgiFj veFWN9Dkr35khqVZqIajADQpdQDTi1UlEe3HdvQseZ1SlfHWN4twvsxdAp3Ay374OoXv xjTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=Kxtv3LqY; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=eAO4oa1z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h14si4292647eja.174.2020.08.06.16.41.42; Thu, 06 Aug 2020 16:42:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=Kxtv3LqY; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=eAO4oa1z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726710AbgHFXjC (ORCPT + 99 others); Thu, 6 Aug 2020 19:39:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbgHFXiw (ORCPT ); Thu, 6 Aug 2020 19:38:52 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 036A1C061574; Thu, 6 Aug 2020 16:38:52 -0700 (PDT) Date: Thu, 06 Aug 2020 23:38:49 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1596757130; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P4nbLAAuSFU/iG/0iov28OXKQeCl8AQVN5QtOnyn6SA=; b=Kxtv3LqYINat3EB9eh1QDQDiHqpFvOTi6c65sT5DLRTJUc4aZKBrpYKlLQ2Ojd3ok4i94r ovVeGvln0I2Fw0xn4bS7sWG9yYDuJNUih1SQlUYsGKe+Ya0ggge+hMVyyB3FGQ/SO7hL8G wEMv3Q8tnEbd/pg+Ki9tiKHrVGelZbxVjwhYJtaV/7IZTs6doZb2mLLBm70x9MsmrMKkcB RYnKFFpM9W5Wn4NiiaGr1KY8eIkUG5WB2QfNPCul+q4Elxvke4D/PsVk3g8UO6msliy+jJ 9AkUI+5ncsPnMq60UdPDPbATr5ejBvjCLJ+kuiF2NC00e6M+mtV8iRCE2z8gog== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1596757130; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P4nbLAAuSFU/iG/0iov28OXKQeCl8AQVN5QtOnyn6SA=; b=eAO4oa1zUFfsd/Ox5wnUqMG3BDdICSbc2tA8tZx/gqL+mXzrJT2MFbkbKrdpD//SCkZPAg eVDgIoUdppGqBSBA== From: "tip-bot2 for Arvind Sankar" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/kaslr] x86/kaslr: Replace strlen() with strnlen() Cc: Arvind Sankar , Ingo Molnar , x86 , LKML In-Reply-To: <20200803011534.730645-2-nivedita@alum.mit.edu> References: <20200803011534.730645-2-nivedita@alum.mit.edu> MIME-Version: 1.0 Message-ID: <159675712976.3192.9635151038817654680.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/kaslr branch of tip: Commit-ID: 76167e5c5457aee8fba3edc5b8554183696fc94d Gitweb: https://git.kernel.org/tip/76167e5c5457aee8fba3edc5b8554183696fc94d Author: Arvind Sankar AuthorDate: Sun, 02 Aug 2020 21:15:34 -04:00 Committer: Ingo Molnar CommitterDate: Thu, 06 Aug 2020 17:03:19 +02:00 x86/kaslr: Replace strlen() with strnlen() strnlen is safer in case the command line is not NUL-terminated. Signed-off-by: Arvind Sankar Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20200803011534.730645-2-nivedita@alum.mit.edu --- arch/x86/boot/compressed/kaslr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index 735fcb2..6d39743 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -43,6 +43,10 @@ #define STATIC #include +#define _SETUP +#include /* For COMMAND_LINE_SIZE */ +#undef _SETUP + #ifdef CONFIG_X86_5LEVEL unsigned int __pgtable_l5_enabled; unsigned int pgdir_shift __ro_after_init = 39; @@ -278,7 +282,7 @@ static void handle_mem_options(void) if (!args) return; - len = strlen(args); + len = strnlen(args, COMMAND_LINE_SIZE-1); tmp_cmdline = malloc(len + 1); if (!tmp_cmdline) error("Failed to allocate space for tmp_cmdline"); @@ -425,7 +429,7 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size, cmd_line = get_cmd_line_ptr(); /* Calculate size of cmd_line. */ if (cmd_line) { - cmd_line_size = strlen((char *)cmd_line) + 1; + cmd_line_size = strnlen((char *)cmd_line, COMMAND_LINE_SIZE-1) + 1; mem_avoid[MEM_AVOID_CMDLINE].start = cmd_line; mem_avoid[MEM_AVOID_CMDLINE].size = cmd_line_size; add_identity_map(mem_avoid[MEM_AVOID_CMDLINE].start,