Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1207269ybv; Fri, 7 Feb 2020 16:47:17 -0800 (PST) X-Google-Smtp-Source: APXvYqx3R0sltFflOBZoDU8nZEo3EzBZhwbCIIIDWe1UaOTNXfTJaCqHTVW+N0lHpvHB7eSAGMwL X-Received: by 2002:a9d:75da:: with SMTP id c26mr1654430otl.40.1581122837490; Fri, 07 Feb 2020 16:47:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581122837; cv=none; d=google.com; s=arc-20160816; b=uvvGlsMe14XaWZnQBv+qb1xJgXj/8ztHbQSAfcff9ryQ7cpYN6LAnz7t9ow8lnzkjg KrIQdUuhNPQUTVTB3174CeSbaNyjqDp5nAhhdOdO0tiEukiE6Ezwi4J2xue18uO8muk+ SSVsDUDmDHBqBDVZRi68Fifed60tPjlb1zhzQzfQAv4lp7qLR6UUj7bJgcWZ818+tz8U 8x/7vMnrU75LCSIt5jpTvLExWCBUPdDqePzRFuz0xhLpGUbI+2DlyolC/y5tJpl6lpgk UwDaaiYTyFU9MeWnzUB42/iZc5JdknBXs0WFQd+I9+hEMNwww+Xy9ZgOPtWzih4XJEAX TjGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=HIScyM8HTPuRFkGrTkGhKjCkbYZS1XwH37oLGXBpCas=; b=AbtxGRXV8QCFCkFoEPOTTMb5a2CANAQebYk+YDa2oJ4y+4hk5zuLnVTUwWWFzu2Nn7 bheaH/AybV9eVVJxOUgdMKOEbRVVWle7cBshA4mCav5f/+woHmrKnJ1FVLbrwq7KoOxf ntIb63BmWCsYRVsFgdodS/ewuLyNmP0cYzrBVmvoQxIZ51lcHoC/Bai9lhgiN+S4pz0z GG8Gc5yHfIcKBzbnyX2GvsLo8TISIH1rLkxirul6ZZt0jXNrvo2XdQvaj6t59zcJ/TBq DgCGC2JqQmhMkDqNHkFWyMj5vqBiZoPkJOYZtatvLfH5mMCsdYYcR9fTrQQDyQR+kWqw lM5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=avXpkzIb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d19si553726ote.3.2020.02.07.16.47.05; Fri, 07 Feb 2020 16:47:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=avXpkzIb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727390AbgBHAox (ORCPT + 99 others); Fri, 7 Feb 2020 19:44:53 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:35463 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727065AbgBHAox (ORCPT ); Fri, 7 Feb 2020 19:44:53 -0500 Received: by mail-ot1-f65.google.com with SMTP id r16so1119031otd.2 for ; Fri, 07 Feb 2020 16:44:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=HIScyM8HTPuRFkGrTkGhKjCkbYZS1XwH37oLGXBpCas=; b=avXpkzIbujb+uPKp91557WSYk1wCOMOMq3jAwBf90XEMptoj/zthaPim9WYa6pipC5 GrjxYNyj/SPOUJFoWmReRB/ZAD09cmN/f+8KN7iCM+7YEIU3rV3Td6NIATO5XKfolCoP vbMNtpiu1bP1dqGRs3qJbZD8ygrGf9mqgAEso= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=HIScyM8HTPuRFkGrTkGhKjCkbYZS1XwH37oLGXBpCas=; b=EhJW4z4Z9Eu2nuSvaA5x+geVEKV6NZmsCAIwyc5OXOHWTznuOdxjpL8sewoOmoKbVQ 07uxDesQ+SV/fZ7u3kIkxdmCjW4n8sKpVHXf7xA5Xc78DahexX7QqnTuGYeBKXvlbMbB 5/CufGMYYp3aZbSMBDOEmW7+GAeLYjxR53osGA4u5zNQ2YYiXqX488gCtKZMSDU0l498 3sEiBkQUKj4xx2ZkTK9onKlj6DCZ+L3dRhzJZyGElpOd3/JGnhqYn2vk7Zg0yiwefVT8 ZWASFUjO5nS6A2cm7aj05mv4IG0bJVXacbYWtiPUj4S9r0MABGlOpKQuUX1hKQgU+1FT NB/Q== X-Gm-Message-State: APjAAAVsuOy3HrKI5veow17JowNI07i3kiZTH0y0VjFvM+iU4wD5IFjp OSYsHuUnB7Pqw4tmpqaCDvtFOA== X-Received: by 2002:a05:6830:18ce:: with SMTP id v14mr1593596ote.36.1581122691485; Fri, 07 Feb 2020 16:44:51 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id e21sm1596188oib.16.2020.02.07.16.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2020 16:44:50 -0800 (PST) Date: Fri, 7 Feb 2020 16:44:49 -0800 From: Kees Cook To: Steven Rostedt Cc: Masami Hiramatsu , Ingo Molnar , Frank Rowand , Randy Dunlap , Namhyung Kim , Tim Bird , Jiri Olsa , Arnaldo Carvalho de Melo , Tom Zanussi , Rob Herring , Andrew Morton , Thomas Gleixner , Greg Kroah-Hartman , Alexey Dobriyan , Jonathan Corbet , Linus Torvalds , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v6 08/22] bootconfig: init: Allow admin to use bootconfig for init command line Message-ID: <202002071640.49BFDA2D1A@keescook> References: <157867220019.17873.13377985653744804396.stgit@devnote2> <157867229521.17873.654222294326542349.stgit@devnote2> <202002070954.C18E7F58B@keescook> <20200207144603.30688b94@oasis.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200207144603.30688b94@oasis.local.home> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 07, 2020 at 02:46:03PM -0500, Steven Rostedt wrote: > On Fri, 7 Feb 2020 10:03:16 -0800 > Kees Cook wrote: > > > + len = strlen(saved_command_line); > > > + if (!strstr(boot_command_line, " -- ")) { > > > + strcpy(saved_command_line + len, " -- "); > > > + len += 4; > > > + } else > > > + saved_command_line[len++] = ' '; > > > + > > > + strcpy(saved_command_line + len, extra_init_args); > > > + } > > > > This isn't safe because it will destroy any argument with " -- " in > > quotes and anything after it. For example, booting with: > > > > thing=on acpi_osi="! -- " other=setting > > > > will wreck acpi_osi's value and potentially overwrite "other=settings", > > etc. > > > > (Yes, this seems very unlikely, but you can't treat " -- " as special, > > the command line string must be correct parsed for double quotes, as > > parse_args() does.) > > > > This is not the args you are looking for. ;-) > > There is a slight bug, but not as bad as you may think it is. > bootconfig (when added to the command line) will look for a json like > file appended to the initrd, and it will parse that. That's what all the > xbc_*() functions do (extended boot commandline). If one of the options > in that json like file is "init", then it will create the > extra_init_args, which will make ilen greater than zero. > > The above if statement looks for that ' -- ', and if it doesn't find it > (strcmp() returns NULL when not found) it will than append " -- " to > the boot_command_line. If it is found, then the " -- " is not added. In > either case, the init args found in the json like file in the initrd is > appended to the saved_command_line. > > I did say there's a slight bug here. If you have your condition, and > you add init arguments to that json file, it wont properly add the " -- > ", and the init arguments in that file will be ignored. Ah, right, it's even more slight, sorry, I had the strstr() in my head still. So, yes, with an "init" section and a very goofy " -- " present in a kernel bootparam string value, the appended init args will be parsed as kernel options. -- Kees Cook