Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1714768pxa; Sun, 2 Aug 2020 18:24:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTN9P2Z9kljWHPIS6Te3OaO+C25oSQq2YzPcRs99CXuMixwHxY8lNlUJFWeXUcOgGyxSuJ X-Received: by 2002:a17:906:4e14:: with SMTP id z20mr14898731eju.541.1596417846874; Sun, 02 Aug 2020 18:24:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596417846; cv=none; d=google.com; s=arc-20160816; b=wALZQMGrUO55jQv1htWDX8bwQJeZHhh2TmUZ7ppAlf8/vlfOhZm9wt7IXjSDFsrq0T m7I5hPffD/Ok4r+Smft0fLvDIMGioIV7nUEns5R57qoKkSf84jwa246EbW4mmBaelizw B8nHndJ3GnAnWrU8VlbkcNeRKfUA4BTO7iOoRIO7MqBXPoKYBmKYkjdlRyai6/hfV62b H8hWvQdbYkYBNnPfhOP2NHTzi9U6q3r8jCZlCkq0bmTbofBYk6AiCtvFrf6nlC8KHsla wJMDyGMzo0IcvayOIoEXZD33CMclwlUUfHtWXkKX83s3Fewmvy/Xge66Cn0hd0G8gmxc R7NQ== 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=UqKzpllSGPPCUJdcTHjuzKk2JONMRxxf8Mio+enWVv8=; b=VIfmYNCsf5I5blB2ltpTyBnG1mupg4VOhIzKHb/CtThFwzAs1tFAKCpqf6Iu9r5K9f EewahEpL9Yi4W+wTeuZoIRzH1vEfC6gtSXxxAArb1ect95idirmZT4IogX3C/QpX8sCz 12tecrUe+24/WTnqPAYQHvorXKvr87VHSZAoCNv9nU5R0kqA/gIcTa2XSOZ9Eic/whfH TU15p1qTliZoKN1a7QprOksvEEzt6fms29KypxeQ0pZIYREDElGVt34gOpGXpgwi3nle zka0AKVq9IcmDPma3vBEd1O2dQ/5+9dCR39imVR99ujl6fncosg6+SCaU4wdkJq5L5ZK JeNQ== 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 t24si9192097edy.465.2020.08.02.18.23.43; Sun, 02 Aug 2020 18:24: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 S1726869AbgHCBPj (ORCPT + 99 others); Sun, 2 Aug 2020 21:15:39 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:33140 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726534AbgHCBPi (ORCPT ); Sun, 2 Aug 2020 21:15:38 -0400 Received: by mail-qt1-f196.google.com with SMTP id 6so27200491qtt.0 for ; Sun, 02 Aug 2020 18:15:37 -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=UqKzpllSGPPCUJdcTHjuzKk2JONMRxxf8Mio+enWVv8=; b=OKAA42CZW6QFPqdsMvPQKYQAZcpP3XSb0FezPhNQu03U47jQ7krL6OZ5RN4rKxOp09 9/Zp8grlGx09aOmebwew3aQWfFoSU4H82s0bPnYjZbNUyk9vku2Fw6OrKgsQKlmcrGsJ hdajTB0hzDpCzQHwE30CTb5eMfG5x+/4aRHq2GZNpeXPrrhtQfX5YyBXQBpe0TZrHCfl cmuOH9j3/c/T2BEPAslvtJwJQwSPzl3tp/HvjZNazdiy+iuExkhtKKldVlB1JEX712bX OazPCtIevBOz6Xh3jmp/NbPXuwvtInl77U9ie1ZCzQEogAkBD3CwQdudV01ES5suCGZz ARXw== X-Gm-Message-State: AOAM532sN8y/1TmBY09C8pgtfoWGsDm9q/CLXWqVPvEhf2yQTSRCvLQA 0tV5mW3f9aUOEN8FdelJF/A= X-Received: by 2002:aed:34e2:: with SMTP id x89mr14144623qtd.313.1596417336887; Sun, 02 Aug 2020 18:15:36 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id q29sm22015801qtc.10.2020.08.02.18.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Aug 2020 18:15:36 -0700 (PDT) From: Arvind Sankar To: Ingo Molnar , Kees Cook Cc: x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/1] x86/kaslr: Replace strlen with strnlen Date: Sun, 2 Aug 2020 21:15:34 -0400 Message-Id: <20200803011534.730645-2-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200803011534.730645-1-nivedita@alum.mit.edu> References: <202007311632.54A7554192@keescook> <20200803011534.730645-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 strnlen is safer in case the command line is not NUL-terminated. Signed-off-by: Arvind Sankar --- 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 903ccdca0551..a5842eea84cb 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, -- 2.26.2