Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp162166lqg; Wed, 10 Apr 2024 20:45:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV+q1s0kzWLhhpSIO9x6p5omw02PD+jx0Wtoq6xuVyLmAdwtNGcoj9U1IzIhHcruQJbUTG0s9k9ft4VmVyed2+2YwwmnSkTgtvB8te2sw== X-Google-Smtp-Source: AGHT+IFpZiO/Jf9iCZYTIJ1WpHkJd+am9fYFiZHy6HBGe/23JIOhz2CTBOLJ59HKHnQ+2qovTBUY X-Received: by 2002:a17:902:f34d:b0:1e4:2879:3a38 with SMTP id q13-20020a170902f34d00b001e428793a38mr3657206ple.47.1712807157325; Wed, 10 Apr 2024 20:45:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712807157; cv=pass; d=google.com; s=arc-20160816; b=fb1qBg5hYHUHYTQ41nQjGec1J9AeoCzqcGyr+zu5JoZALj6oiSwgj+Qe6pkqI/OERS mgMO5QP6G3d8uZYAprN4LzXZNHDTvsCNRY6cuChy7YwK4AS0y+k5i+0tHVG15MqqEw8Z g8KLjTpYJeeSll/YyHxh8Jk9kI2XZyzTlCBK2aTFmeGo1ec5vPq8BKuoj8tBzZJwFHg1 b3k+mveyKxrG2u06j5TS03f4JwqtqKLjfRNzPRCq7FAMj9RpYzWiOZ8pcMNRrDjGgwhs lImm4q9uKhEhTP59lFdC4g4aP6Jo50oWNOLJS/JL4K8BkZuTjCqExUhkRh2TVw1ex35J B3yw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=8ZCVQwQdR/DxF6xfmiAlaAl/0HcO8Z3D8nID8IjezKs=; fh=E0YlPQ30c2xg0hq0xlh1e0tfevt6dL/DKZMhnq6FdpM=; b=wBJXz0jYIxkp/yNE2uVZUO5EV3QIiKG1ihC4zrN7S6jbuKKbA6fb6PvMLv4JUOJjX5 ImtHNOEYbBIEJEAMFaOu5xRi0TEPzNjtOasEQ+c+doJJGME8V1wiy9DC/FlmshAchTcP XN/JaFzDrhhDeDX6IC1ny6+gKfGOAFCRf/NrPG4QKP1hdTf7CoLTQ5lQzZYyJOU3Xm0x qmA+8wKcWPUu4pat3mc3BJiVo3uLjg1mnBQktpHttpb8h9NW3rGEg5KNQO75xrKUgeFK U3rNdQol0NnyAaeVeg8wbXTbPkDKv9IfeyQJzi+riqJ2f9uaYWzv6HmOst9iRgJ5zts9 gykw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gE8y4XgB; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-139702-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139702-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id n16-20020a170902f61000b001e2ade13084si491697plg.249.2024.04.10.20.45.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 20:45:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139702-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gE8y4XgB; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-139702-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139702-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 24F5FB273F0 for ; Thu, 11 Apr 2024 03:25:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D398D13BAC5; Thu, 11 Apr 2024 03:25:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gE8y4XgB" Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEB5E13B58D for ; Thu, 11 Apr 2024 03:25:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712805932; cv=none; b=bFHFqN3xDGLiESg/EFKEnrtGRG1V6n/g3sBUufNW2N8F3HLAwUU6O1CN8jdbhO08OvcZCPaMAx6kjlf8VRHA2CKqD0P6cC+n9e5PsgVgWeNiahrDaXSAKRDiHXnB/bJBJgy/UOK+wz83fVY38rhHtrfz2+gn8MYPNoSUNxH4IyE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712805932; c=relaxed/simple; bh=KeJpTltWvp34aLVwOhgfYkJ5qkUafemwD40qWwAeh3A=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Z8RY+sd3TjAqfVGSi/+0Zsjy8cx2H66SSflQnilQ42hUlipyEtZMOQvSHaY1djqv6seyY8AO4q8RLMCfGTEbrIDLb0415lcpQn35gmmuULIOLoWD2Y0mOCz27b90oz6m6zkmSWDOA0kfbyv68Bk5KXRrul4yWoJHk8EMEXHpZ1U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gE8y4XgB; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6ed04c91c46so5411505b3a.0 for ; Wed, 10 Apr 2024 20:25:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712805930; x=1713410730; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8ZCVQwQdR/DxF6xfmiAlaAl/0HcO8Z3D8nID8IjezKs=; b=gE8y4XgBc95HY0UikWCKZ+TZ/GdyGxC886oMCzSpzIUTM5L0cD1JaFrxXNvqNOP4nI jsjbb5dG60YsIsaYC+SVSB5NQquyHBmgGei8Cqxexx99f/pzOeZz8xTYKjbt2Zlan0/h 0L710SzEEw05MBE9YZl1LuKgkrev1m3HEOfS1iKfLWjY2wcEYytyyhniESm7J9xfMHpy +GxjiaM1RJN/k1bNge3yfsaWU0dMR28WZ4h7kv1ysxowgpjlptcJeY+nMgjBhOvNt9eL RTLv9d9oMYv5/Gu43hBqlc5PxQxDz1YGE9+7pBe787kXK4xexobAo8xtOZh8RmWFoWps pPtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712805930; x=1713410730; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8ZCVQwQdR/DxF6xfmiAlaAl/0HcO8Z3D8nID8IjezKs=; b=kMNAO51qG0dG93UN/fCeMi5Y/DdPHxTGmc72Yn3UDZGcCGpSK2gqxnC5O3G95jykpC sK//I/PQHxnPZfUbB19Z751cLEqlUFEJHcnnZP7gUj/NjS15N4ZxKvBmLLiOV/RAgJz2 1d6Fci43Ze9CYVtF9C4ECx590NokHKeaHx78bofD6efnkc2NjQqictohRMqgOSKnb1xx dqEZTkx7R1umIWmdBl9rz5+c49UrE1fNZRJ/36ec9URSeBCR5J+0NYWJQa2igq0PY5yb rx4grHgzBgSUHlgyrJqS0g3cqhp646sRf8BUF0s9nZeelXggn+b/vBbZezUAHUSxcLal Qxuw== X-Gm-Message-State: AOJu0YwseB2nnwSI1g0a9FMnmrUUA5FauwHmSDi0259ysSufNsj9YBUd FGrk6brcyCX1UO3+AfP4RQOiPtBRDuRQ56MLaCQWIdTS9Gajtd5/YOk4FrYM X-Received: by 2002:a05:6a21:3396:b0:1a7:23ae:92c3 with SMTP id yy22-20020a056a21339600b001a723ae92c3mr5428278pzb.12.1712805929823; Wed, 10 Apr 2024 20:25:29 -0700 (PDT) Received: from code.. ([144.202.108.46]) by smtp.gmail.com with ESMTPSA id je14-20020a170903264e00b001e22e8a859asm297139plb.108.2024.04.10.20.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 20:25:29 -0700 (PDT) From: Yuntao Wang To: linux-kernel@vger.kernel.org Cc: Thomas Gleixner , Andrew Morton , "ndesaulniers@google.com" , Josh Poimboeuf , "Peter Zijlstra (Intel)" , Tejun Heo , Christophe Leroy , Krister Johansen , Arnd Bergmann , Geert Uytterhoeven , Mike Rapoport , Yuntao Wang Subject: [PATCH] init/main.c: Fix potential static_command_line memory overflow Date: Thu, 11 Apr 2024 11:21:55 +0800 Message-ID: <20240411032155.208042-1-ytcoode@gmail.com> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Fixes: f5c7310ac73e ("init/main: add checks for the return value of memblock_alloc*()") 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) -- 2.44.0