Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp399184lqg; Thu, 11 Apr 2024 06:34:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKucRe6vvEvFPIiIevGDeoIsqz58LuOjcg7w8K5TBrWWEvGRtZCNwN3ZoXvwavO7/RW5CnDXh1QejmNNhQ3Z54qeaK3eQyDrT/VZiObw== X-Google-Smtp-Source: AGHT+IEAZphCzph8F695p9L4sowSmx0sLZolgJXjW3chfh1HxT9tx9mW4+61hH03PaIgHhXBVMdY X-Received: by 2002:a05:6e02:1c28:b0:36a:686:bc98 with SMTP id m8-20020a056e021c2800b0036a0686bc98mr6787986ilh.14.1712842446177; Thu, 11 Apr 2024 06:34:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712842446; cv=pass; d=google.com; s=arc-20160816; b=LymnQBvfCoT15uGtS25877dl+OzVbFdSWuvQW8rx79/NENK7F1+nGDGdysh0yC1TVx 5YBeZYwWZaPxBSx50z7PoFCz0+rFku/SiKi0zrtiMnKUgiLJKPR8C+tBo+1qCIr+6mo8 osskQ5qMeP60muyzrGqzH8Wx/GuaZTy1r6MwA4owLqMK5tTDXsMmYHeQQmtbwiQZ2Rnb a1k2oVUqywRhqb8YI3ogr93FqPLiBcneod2JPlnFRFMnmKQ21tIxgKjG3AkohcPUgdAj KC/PDRQiyQ3LLH4rH4et/lISo5nbt8aOahJNKMr44sI/NeHUvMlfjjI24uMpFaAaRLKC cMkw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=944W6AfqSIjIMuZAnRu/R/S01rKFD80cQ2wYdtPIZqQ=; fh=uOOLzZN27MLRFjpUp3xc085XbM8fNbONn9080vweFM4=; b=jSXkAOG0VUOq10e1Pgq1AJZ3JG7bZ8G2o0RrEpNlq4wDrl97hBaBlfiL8T6ZmVE8dX pIM5UnX+iif6N1pYy0pbLD/WD0YpgK2hcY6JGlzvJwXeFzvxGmUi7aPJMldO6lPmXO7l P+Cae2gvcPSdN45V58EgZyN8YKdBzSFhRjggF0X595ZFsQdwI0qwDZmFSrW3kkJTGr0S dLZpcnBZxyS+dXe11JtsAikZJPnIutONNYddDOWzPeGvHcrBT9MCUHcK74/nkM2POS01 UcZ2eXU1aEQDY04jPutJYGjsq8DHE+w0ZJw8axc++wuexKljs0fQjogl8/aw6BM1wwre Ilaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MSby2ypO; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-140495-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140495-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id a28-20020a63705c000000b005dc89648272si1306088pgn.24.2024.04.11.06.34.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 06:34:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140495-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MSby2ypO; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-140495-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140495-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 441C7B24A16 for ; Thu, 11 Apr 2024 13:22:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 17A0314C5BE; Thu, 11 Apr 2024 13:22:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MSby2ypO" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F82A28FD for ; Thu, 11 Apr 2024 13:22:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712841761; cv=none; b=nhRc5nhNv+xUTjetuqFT8anL+VdQ0Zhc6HtoK6kK6dYhpuRTdMQf+4ZcDqbII54QvmKgezQ2OHHq0j/nKzYYrKKPGQswpIUeuipm/JWsyiZwdywlLHNWK5BKhpXlOrfBBGhnjepKQ+dbcuiWBwViXClUyQFUq+lz+HF9lTeFhZM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712841761; c=relaxed/simple; bh=oFQCtMDMv3w6WRwA1HLjJqSklYOlziJ7QD5xsD3KecU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=n5ORxkMOcYnYHXjTnazxaR5w4gHwtVrfL5gMvysGNmoNeK/3MTvRor0twWFJv7svmEpRH6iuIusZJQpFe5e/3PxjW1bJ8nK5OweqaEPpjeO5eXXG6oVt8pso1Ae9xwwogXuqfc07YZa/5N2nN6fVdlI2akkf4ouc25tISyBrOvE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MSby2ypO; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AABB5C04D3C; Thu, 11 Apr 2024 13:22:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712841761; bh=oFQCtMDMv3w6WRwA1HLjJqSklYOlziJ7QD5xsD3KecU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MSby2ypOwMO5LVMLeZ9cpiWm8pCYyRO/lkviEGzjZpwLQcLeWHU3HoW8Zwkcfz03A jIvCjpX2uOAxPnLw3YkRmynzzBFcoc0W+/vXMto5opv3qkoonpyGZmt1WKXyphsgGG u3voYUfF7R16ZkJ4ah1nu241bAmwh3byMTRkjUj1nSlz+zhuiFMP8cJlFUrn0jmhCj w6Z56veQVpFNsKbQhDuF68oXfIz5Lr4t6fGN5nME9mSvm6qW3tlPaD5ET7ylZJuaZP Intt8OWUs+KPYbQc7WFu253n8+coGwQH6saMAd/4dD8ry7D4/URbAitIQ7pTBcjo6n lEPZiEo/bq8kA== Date: Thu, 11 Apr 2024 16:21:37 +0300 From: Mike Rapoport To: Geert Uytterhoeven Cc: Yuntao Wang , linux-kernel@vger.kernel.org, Thomas Gleixner , Andrew Morton , "ndesaulniers@google.com" , Josh Poimboeuf , "Peter Zijlstra (Intel)" , Tejun Heo , Christophe Leroy , Krister Johansen , Arnd Bergmann , Masami Hiramatsu Subject: Re: [PATCH] init/main.c: Fix potential static_command_line memory overflow Message-ID: References: <20240411032155.208042-1-ytcoode@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Apr 11, 2024 at 09:23:47AM +0200, Geert Uytterhoeven wrote: > CC Hiramatsu-san > > On Thu, Apr 11, 2024 at 5:25 AM Yuntao Wang wrote: > > We allocate memory of size 'xlen + strlen(boot_command_line) + 1' for > > static_command_line, but the strings copied into static_command_line are > > extra_command_line and command_line, rather than extra_command_line and > > boot_command_line. > > > > When strlen(command_line) > strlen(boot_command_line), static_command_line > > will overflow. Can this ever happen? Did you observe the overflow or is this a theoretical bug? > > Fixes: f5c7310ac73e ("init/main: add checks for the return value of memblock_alloc*()") f5c7310ac73e didn't have the logic for calculating allocation size, we surely don't want to go back that far wiht Fixes. > > Signed-off-by: Yuntao Wang > > --- > > init/main.c | 8 +++++--- > > 1 file changed, 5 insertions(+), 3 deletions(-) > > > > diff --git a/init/main.c b/init/main.c > > index 2ca52474d0c3..a7b1f5f3e3b6 100644 > > --- a/init/main.c > > +++ b/init/main.c > > @@ -625,11 +625,13 @@ static void __init setup_command_line(char *command_line) > > if (extra_init_args) > > ilen = strlen(extra_init_args) + 4; /* for " -- " */ > > > > - len = xlen + strlen(boot_command_line) + 1; > > + len = xlen + strlen(boot_command_line) + ilen + 1; > > > > - saved_command_line = memblock_alloc(len + ilen, SMP_CACHE_BYTES); > > + saved_command_line = memblock_alloc(len, SMP_CACHE_BYTES); > > if (!saved_command_line) > > - panic("%s: Failed to allocate %zu bytes\n", __func__, len + ilen); > > + panic("%s: Failed to allocate %zu bytes\n", __func__, len); > > + > > + len = xlen + strlen(command_line) + 1; > > > > static_command_line = memblock_alloc(len, SMP_CACHE_BYTES); > > if (!static_command_line) > > Gr{oetje,eeting}s, > > Geert > > -- > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org > > In personal conversations with technical people, I call myself a hacker. But > when I'm talking to journalists I just say "programmer" or something like that. > -- Linus Torvalds -- Sincerely yours, Mike.