From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 BCE133A6F0F for ; Thu, 12 Mar 2026 19:11:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773342709; cv=none; b=g+0jSW/6rOw+QUYfe5vaGpqDdFp5wiLTcdNNmg9/s73p7M1fe8NvzpouPJg8HRwk6JL9VJ2t6XKifRNVonjJLvREDUIdPDzn5JISH7yk4o3gzNRPWuZVWbUoAmiYx51cxWaTuvUdvLL3Yln614pvZfOqYPW5SSDtaX9dr8gb50M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773342709; c=relaxed/simple; bh=K7t6TixnSC5amlbb+BTN1wgZlFUmLS7pMFxwMr59PtI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bguO3a+l7eILjd9mzMJPnRJNzQ/bc96WVMSg48r4PuCALEqN9Gx0wyGp+6tt5d70r9OiggeA5Wm97zYGIIqnsu3US7EAHz0tdGVyIOo6fAGPr8A9h03jh6Re69LgaZjrsMfr0qwGu5aGN2JcBc9fCKZZtViTbM0CiOEwVmXLA/k= 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=lYmO7q1s; arc=none smtp.client-ip=209.85.167.54 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lYmO7q1s" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-5a13d1c6f25so1486310e87.3 for ; Thu, 12 Mar 2026 12:11:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773342706; x=1773947506; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oSs15jicLNxatcInmbAogDjkpXKXGRLDfNz1kmJ6CQE=; b=lYmO7q1sbbgbMiLOMOXLnU7e8gcWBcRgYanoKlaomR0/nGWcXNhNdr0DN0hSt84mTw UOpPcuLW8uC69uj24xJCTacugzW+LDn9yEWLQX7RA0Vt9SBQRBffRp7PAhYBOTlJlYRN fn5FpQN4MqO/FK9o6bFqud4a6Zeh5WLOYVvTx6ljlHk66Adr3Gkk0yHsXbEZ4yP3XhZl J7dEAt59XExfvDw8nC9Lntvm0eyEqPw9JQDjw/sQmDSk5Xk9SzquSMD4bCRsBbYjVS8s rxUzORJKWx7uot3LCqu0YpfEPXnramZ9RKhhU2NJozaiJg+0e5pnds6YMos61UdGxBLL rcRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773342706; x=1773947506; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=oSs15jicLNxatcInmbAogDjkpXKXGRLDfNz1kmJ6CQE=; b=ciKeVEtU3MMyjSiYnmswVFCpsXzolKw/ZMmZTRuJIsrQ844l583lqWMOK+epXCMlpv msGMprpcaDoVsS/NJzo5n59A9KJqk1E6oPNKCM4O1JrKW9tQfQ3AUEeiyW+OcUWzvazf uAlsDuxP4vvsgynwZpyNvrX1Xp1QPyWNmx9Zo4lE3W54iImgApvYZ+mdIrbD8ExLAwRP eqRafr/jusNjMPnENeCrOssJ/4+F9aqsYbRFo84di6XHx/zv8e1ZpjlGeEwHuH+cSwCQ q2mOKGGKuH2phUW5xDjofT7UiseiWYv9x+VkPg/pCMoqSMeuDP7cGOY5h4oG+ujODGD5 RTSw== X-Forwarded-Encrypted: i=1; AJvYcCXvxA5BkwtFNav5CxGUezJ3TPIgg/L/QPymXtwi6D/FO4cGhOw7nudeCx6gqf5evaWEppbR8YuHALVXW90=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+zsGETNlR4p++wjwo04yxU6vgs41YCMgzd7PfUxfzafhRiLoi Gq3LYAG5CZHpw0vB1LHfAmFSMebxl5sx/FCvXz+vLkSgAJnWn9pVO3eE X-Gm-Gg: ATEYQzyTbjKymC8lV3Yz0ncamN20Uxvl79iSWnmyLF9506F7RC3JlPcdA3Nqva9qfk7 /V4P9DGztvOcaizbn7Apny1Wa50tKk/JBTteH4TcouASnvfPUAHZornfJXNc2nM7UE4D2c3LSEX ZMoklBljElDa0KWfKTIO8lWwkDVPFUbNZ/WDHNqlTnCs0ia8IFiPQ0MmhkwCzRGC+Rq8ogLsIZt ZdhwPfQzIbZhXllR6D0vD70F66UiKKDfuPtDWsfCpcXI3sPiKEZ0o2rvPhRwUeG0TeTToRhk7kX Jq0ORnB4wEa5zf+tnGESsHnl5gy70bbcIpdZW82VLnTDVmcCX0UtKAlhpVhguOy2MOJnt7JpOwq wufjC9Io2N85KvEGitCprldCp4PgRjJS2IGDRcQt1/UXRxNSQDs2EyNCFXla1oRKTbn4soqHxxm Tt3RVgL6W1jNrphy+G30nb+MOPQuIVNvgzOJ1K/Wd7CKDBb7Qai+S0+3wHoO2E2/TyIdQ5UcU= X-Received: by 2002:a05:6512:31c1:b0:5a1:43cc:9fbd with SMTP id 2adb3069b0e04-5a162b06cfamr197164e87.36.1773342705775; Thu, 12 Mar 2026 12:11:45 -0700 (PDT) Received: from ubuntu.. (static.159.107.27.37.clients.your-server.de. [37.27.107.159]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5a156375198sm1112249e87.88.2026.03.12.12.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2026 12:11:44 -0700 (PDT) From: Josh Law X-Google-Original-From: Josh Law To: Masami Hiramatsu , Andrew Morton Cc: Josh Law , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 2/3] lib/bootconfig: check bounds before writing in __xbc_open_brace() Date: Thu, 12 Mar 2026 19:11:42 +0000 Message-Id: <20260312191143.28719-3-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260312191143.28719-1-objecting@objecting.org> References: <20260312191143.28719-1-objecting@objecting.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Josh Law The bounds check for brace_index happens after the array write. While the current call pattern prevents an actual out-of-bounds access (the previous call would have returned an error), the write-before-check pattern is fragile and would become a real out-of-bounds write if the error return were ever not propagated. Move the bounds check before the array write so the function is self-contained and safe regardless of caller behavior. Signed-off-by: Josh Law --- lib/bootconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bootconfig.c b/lib/bootconfig.c index a1e6a2e14b01..62b4ed7a0ba6 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -532,9 +532,9 @@ static char *skip_spaces_until_newline(char *p) static int __init __xbc_open_brace(char *p) { /* Push the last key as open brace */ - open_brace[brace_index++] = xbc_node_index(last_parent); if (brace_index >= XBC_DEPTH_MAX) return xbc_parse_error("Exceed max depth of braces", p); + open_brace[brace_index++] = xbc_node_index(last_parent); return 0; } -- 2.34.1