Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1589946pxa; Thu, 13 Aug 2020 11:59:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzy6P1EyeEVgVdipvbc7AoVjNih+n7VYSsE/+zl2nM7mD1gaZQaNt0TKyhwdgh/0/IWpMDF X-Received: by 2002:a17:906:5f8f:: with SMTP id a15mr6447808eju.291.1597345158717; Thu, 13 Aug 2020 11:59:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597345158; cv=none; d=google.com; s=arc-20160816; b=i3d4TXokKgHwkS+NErPAWG/HApQ1AliDmJt17L+6jAO849kGjaySO0b6JYbF0Yd0fS KhyqOrCjywJ8B/wkUzbSFVOZTifzoy5c79f69WXxMjAPtLeNBQdzLR2Y/TCfESXyeNni TM5hQWywyPZCS1/owbqXqN2xw5791xLmmJI/cifuEqzt+ZZ/OkyIiyX0AbRCYAhnheSR BHQgLYpAbyCEWFb7TpMh6In9uxmcZuOt00iNez8SMeBb+EvOqbCRw7FWQ9Vxf7QUpK4u +K4KGGI7TxC/GgKPJR3lyBuDrZamCrx6+iFTkzxmjsk1Sol/uFV9yD6ONWIl19nk9NfV M7Eg== 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=CIy+fn9MiJZ5T8cf9c31cog88Zabm8xDN4P7tYVMCqY=; b=Rrx84tXU7LF1s/37KeG9DV/vbnZtg/uW62GzoxjlYz0S9bMPgkq+9PawsmAdfU1MyH pS9dBDH1gZnpgzny3IYbv6E0XbkKWzrHkD5Tw8zDunoCk78NGs9yni7VJmwhg5x6/x5G vo2TN9O8rAWsNEE70yCMkKtg7NxSxE4sbVCMM41D0yDZDx39ZpoR9+Vs6UsDTUgL2vYG l9AhVR7OdvlL3QS7aZPITK7oJ1omoNgQ2zHH5tJ5v9umyMywJqq2Ce3bNDvFT9vBGZ1C R9JPz2u1/wAl7BTwzIPN8ogJ8zPUdzJZZXMbHb2k7kLe1TzewSrUG0m/BUxRQn7N6D0j kkNQ== 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 cb26si4035840edb.2.2020.08.13.11.58.54; Thu, 13 Aug 2020 11:59:18 -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 S1726651AbgHMS6S (ORCPT + 99 others); Thu, 13 Aug 2020 14:58:18 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:42461 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726167AbgHMS6P (ORCPT ); Thu, 13 Aug 2020 14:58:15 -0400 Received: by mail-qk1-f194.google.com with SMTP id b79so6116548qkg.9; Thu, 13 Aug 2020 11:58:14 -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=CIy+fn9MiJZ5T8cf9c31cog88Zabm8xDN4P7tYVMCqY=; b=I8NhRCNaTgY84w1+AU82ikN5cYokwg+gzcWauwrABaljcCjA4Ri2TB6y9V9RUjckbO VsWsvgNEJuG+8VsbUWGwpyvbtjqSxPk5TswhB31XHgJP/v1dGJlVVCT/M9Rwg81HX4LP 7ub3P6QQl9derlv6ISNMFJyJSv/OLwtmwrymBSdkmj6KKXtLRjCunPJgEH3CopDavJYF Lh/+PkARW94dfog4RP+OKCcvJBJ9paF2RISEwp1gLKgswCbS3eZQMm02t5wGYvhLrZQi 06AQhg4M54Qq68Lyl7kchekkchMzWFP/BtsA757OKxryk82ELCHmBf5QeTKhRIlfK/Vx FzeQ== X-Gm-Message-State: AOAM5328EetecWlV7ZA2FZRLqwh8PMdSDnniOb5JqkaM40oBPFQgKd6H +Fp+F17+eYuRinZRvTLwyRanvwGb X-Received: by 2002:a37:a746:: with SMTP id q67mr6054586qke.93.1597345094460; Thu, 13 Aug 2020 11:58:14 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id c9sm5994563qkm.44.2020.08.13.11.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 11:58:13 -0700 (PDT) From: Arvind Sankar To: Ard Biesheuvel , linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/3] efi/libstub: Handle unterminated cmdline Date: Thu, 13 Aug 2020 14:58:11 -0400 Message-Id: <20200813185811.554051-4-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200813185811.554051-1-nivedita@alum.mit.edu> References: <20200813185811.554051-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 Make the command line parsing more robust, by handling the case it is not NUL-terminated. Use strnlen instead of strlen, and make sure that the temporary copy is NUL-terminated before parsing. Signed-off-by: Arvind Sankar --- drivers/firmware/efi/libstub/efi-stub-helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index f53652a3a106..fe5103086e27 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -194,12 +194,14 @@ efi_status_t efi_parse_options(char const *cmdline) if (!cmdline) return EFI_SUCCESS; - len = strlen(cmdline) + 1; + len = strnlen(cmdline, COMMAND_LINE_SIZE-1) + 1; status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, len, (void **)&buf); if (status != EFI_SUCCESS) return status; - str = skip_spaces(memcpy(buf, cmdline, len)); + memcpy(buf, cmdline, len-1); + buf[len-1] = '\0'; + str = skip_spaces(buf); while (*str) { char *param, *val; -- 2.26.2