Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp37198ybg; Mon, 27 Jul 2020 14:55:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuwtrD6yqSYugrrZU4jjY+cTlzV6c8DhK3oezKKF+dv/iSEbp9gAVSBHroGJk+5b4fIXeY X-Received: by 2002:a17:906:2e51:: with SMTP id r17mr10738891eji.308.1595886906962; Mon, 27 Jul 2020 14:55:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595886906; cv=none; d=google.com; s=arc-20160816; b=S9SwcIr1NDmskNiTPf5f2/1Pf1jHMg00dPp73i2B9PhY3kZxZg4tTkHaW585CmqW5A znAiHIbS3dOQ78k4/5XQ7UMvXojgDDRgdJTwRejIMkdybA3tWIZSxK4vmdWdJDxxpLmr 0FTDIfYiyovm48x3d8aHbqcOlaQxqjatazthXyW+j4zG7pwAoZYOe0iY3Ht0FbIY2yuO imBjuLqGhGRVemsbRLYGcaHhuLL0vkJjcV6R6GLajPr5T37b81bRfmfaTxQZiwLTWZUu jNm/3HRrjw8FJsg3A8HqU2T/cfBxNhjnFnppwJY8Ke+gCiEeVPDbaNaEhfr551T2t4iW ZnyA== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=FKap99YMpd59dOGOX7zP3mBQNGnZwMBaTyLtvOGre74=; b=xztpApWHffCbj9HvGJuwnOw/ODI9JQt/K3ouVElKQ417RnSlb7FKWNwax1RttxtI6M t+w3ie8iGkffrdJxiMCqRhEA7HLNuuJXuAvulUl9IPvBakqsR4VpMpJIsGlIgVxniCaq 0DavnH85iguxgYHhhUQbcyS/kBjb7JpGbVY8nEi3xCYkyPWr4LYVjfIdGyAENmPKb6c6 DGGahazvPE/RWhMkuSn2mjC0JxbKJDMkQXrTyiBE6sNhg8N95+q5hAV1kb/frmbEzt3G j9D+wkHvIbyKKJ8oGrGimBzep+Qy5h40771Adm25dN590G8F8i5tmhblHM03X56QQhZI YCyQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce7si1293159edb.85.2020.07.27.14.54.43; Mon, 27 Jul 2020 14:55:06 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726824AbgG0Vuw (ORCPT + 99 others); Mon, 27 Jul 2020 17:50:52 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:34089 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbgG0Vuv (ORCPT ); Mon, 27 Jul 2020 17:50:51 -0400 Received: by mail-qt1-f196.google.com with SMTP id x12so4944772qtp.1 for ; Mon, 27 Jul 2020 14:50:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FKap99YMpd59dOGOX7zP3mBQNGnZwMBaTyLtvOGre74=; b=DYui5yupTx+ylvYnX4HKtYDA/0ZZuYurhqNAWuFDsH8Z+OI5bGQlV6Mf5IRrjjBFgT IUNPDGwXDWXHXL+jszXpFMOe5EA2Mur1HbmjYhZwVF7AeBFYX2BRFZtf1dngDCqREkET jISwWRGk6JcE8x7EJHPJAIMSabVuwzc1y60AUUV8g6Z+TaKvZVzVrKAyT3oQsdnOFbaq dj+8GJAqi+DRbeU6HONA4SIfzrTOY8QffzG6JGvfxd3FuD3Z3SZkcG+RjJB0MMm37STy NT++CtqzQ3G5GDQyegPX/8H1hsMfy+6kizWi+5hl7mOvxHCb5b4F//VUPCoJW+OgdtvL oXLg== X-Gm-Message-State: AOAM532wJDGIUbZjlHGhclWbmIURzpEvgbr1geMCFvuJ6wviFpU143pS qhhQR3z/47UnUtnf65mazJY= X-Received: by 2002:ac8:4e86:: with SMTP id 6mr24453080qtp.341.1595886650384; Mon, 27 Jul 2020 14:50:50 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id n90sm15629338qte.21.2020.07.27.14.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 14:50:49 -0700 (PDT) From: Arvind Sankar To: Kees Cook , x86@kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/8] x86/kaslr: Make command line handling safer Date: Mon, 27 Jul 2020 17:50:40 -0400 Message-Id: <20200727215047.3341098-2-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200727215047.3341098-1-nivedita@alum.mit.edu> References: <20200727215047.3341098-1-nivedita@alum.mit.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Handle the possibility that the command line is NULL. Replace open-coded strlen with a function call. Signed-off-by: Arvind Sankar --- arch/x86/boot/compressed/kaslr.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index d7408af55738..a4af89646094 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -268,15 +268,19 @@ static void parse_gb_huge_pages(char *param, char *val) static void handle_mem_options(void) { char *args = (char *)get_cmd_line_ptr(); - size_t len = strlen((char *)args); + size_t len; char *tmp_cmdline; char *param, *val; u64 mem_size; + if (!args) + return; + if (!strstr(args, "memmap=") && !strstr(args, "mem=") && !strstr(args, "hugepages")) return; + len = strlen(args); tmp_cmdline = malloc(len + 1); if (!tmp_cmdline) error("Failed to allocate space for tmp_cmdline"); @@ -399,8 +403,7 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size, { unsigned long init_size = boot_params->hdr.init_size; u64 initrd_start, initrd_size; - u64 cmd_line, cmd_line_size; - char *ptr; + unsigned long cmd_line, cmd_line_size = 0; /* * Avoid the region that is unsafe to overlap during @@ -421,12 +424,10 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size, /* No need to set mapping for initrd, it will be handled in VO. */ /* Avoid kernel command line. */ - cmd_line = (u64)boot_params->ext_cmd_line_ptr << 32; - cmd_line |= boot_params->hdr.cmd_line_ptr; + cmd_line = get_cmd_line_ptr(); /* Calculate size of cmd_line. */ - ptr = (char *)(unsigned long)cmd_line; - for (cmd_line_size = 0; ptr[cmd_line_size++];) - ; + if (cmd_line) + cmd_line_size = strlen((char *)cmd_line); 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, -- 2.26.2