Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2401252lqt; Mon, 22 Apr 2024 09:38:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVyBqNskDpxQYJuZjmzrXqnpRAOZyJs0/ly2kNGotPHm+x9Q+00E9E8qYAYgmNtdOKQSzYXt+vvEWzsgKDiGpkUBeW4I76iT0wXKrRUKQ== X-Google-Smtp-Source: AGHT+IHnPjBUspj6mYNYPHhihC3XA+jrYbos7ltwkvmJwr3U4lGk0nx+QO4EmnBl5Gbp8r/gOXc6 X-Received: by 2002:a17:902:a503:b0:1e4:514a:55af with SMTP id s3-20020a170902a50300b001e4514a55afmr8821366plq.68.1713803927445; Mon, 22 Apr 2024 09:38:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713803927; cv=pass; d=google.com; s=arc-20160816; b=PAJcP5RwHmv6eQXYZDby7c1ZBw7DI1Ypw3U9NUH+zdaIW2n5NSmRE9PAid40/YKMKb kHH1uSQa8ss3BMjF8mjKOPobPXLpvXMq/BfCnCsiIoFFDg+mxbQ0srNj2phRCnSO80pM OM8GT1jE3bsaxraCwZwln9UDA4I9iROEvsKszqwTQJw9JW04nKpiME+uc8OnOFt8xbmn zmgIpQIPR49G6C4s6Bfnfk7H4re2frzI3xdjLYPtpceKwtoq05dz83WzH+t4cYq26SBR xtYm8FzfX8AIeB4R2RMAWnBShX6ldpQp7hRcrKy8iV/y/nQFiRWHBHx+GcGvH7k2Aopw GOCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:from :dkim-signature; bh=W/RJrrrs8RwvpYrHG7SbHwPY/r0CKqLeGFzxu6oxqWA=; fh=K221Ly5th/uieNG86s5/VzpS5bbhX7bXvBhbBbAcIZ8=; b=UR2z55AmZiT75NGe1ZSZpLHRg1evBw9iMNWpHfsinchVb51zuS5AevZgipkB6qVtX+ togC/jNCmKMjCICYsKdC70mX5Q8p7E6StRp2x0/CN6pgOvXL6mk93Toi7n3/k4IdZFmm UGQcujjjlPNPdJtIlduMLAcZyMya+mo2Zd6skaW6Uhk3FdZY91w8jF/QV/oHXfgEwZD1 F23LQGTzzDM0o5OAWGeOrpZBFoO3yY6WxKuwQ0LjOlfb8a1ZqgPkb8Nn0+VU6vuARpDW kxvZGrzzlyRtBkyB7fe/zU75ScyNJxTNfglrs2SuAAI7SvYHnEs2mi3k3pgXMrYjY0R4 uXhg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UOYb5BBV; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-153712-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153712-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p5-20020a170902ebc500b001e3bffa498bsi8160586plg.389.2024.04.22.09.38.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 09:38:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153712-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UOYb5BBV; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-153712-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153712-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 38A9A28299C for ; Mon, 22 Apr 2024 16:37:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D88F15381F; Mon, 22 Apr 2024 16:37:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UOYb5BBV" Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 875CE1DDE9 for ; Mon, 22 Apr 2024 16:37:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803874; cv=none; b=fW/PMUSImVHFxhCgt+Y57FI6rhBi7ihbhp1aXbzAsWrl2+LZckM+6lm6ozklOCqqLjRTHQL4vCSAfuLckdnJnswQd95/pBtASJcmF4vasS5Tlr7186aad75HD9IyLOH68uI9c1Xr3j21BvRBvE8dUlEG3h0jYMfYhHZp7C9FUAg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803874; c=relaxed/simple; bh=H6lY9kh62C4YQstjcqSOklbN1ZNSivp/MHHRCWngx/g=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=Y2CGvSUTc408Lin6FTF+Ian3ZCL7OPZUGtBrfWeOPmRcTVvVwnmK7HS+D9CYZzZ79gz0tlYdyEE3wfejQwTo1aYLOzyxiK198uYNYLxGcduNcYDgSj1OARFCJpSw2shaUBe511nsmiyXnQeBZLMbCRruiAsKSpbr4ssQkvCOY2E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=UOYb5BBV; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-41aa21b06b3so1834335e9.0 for ; Mon, 22 Apr 2024 09:37:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713803870; x=1714408670; darn=vger.kernel.org; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:from:to:cc:subject:date:message-id:reply-to; bh=W/RJrrrs8RwvpYrHG7SbHwPY/r0CKqLeGFzxu6oxqWA=; b=UOYb5BBVre+5E6nos39Uiao3CK2OxOG7MUlmz4HX7BqHBw1TSpDWuopt/sKarjM1kF rrCRifJI9Jd4XUemwN6KvHZ63evdivIEU5hnfeMAZjkmn4euqPBTldYEgRI/iipkG93+ OXru28yYUvdUMfA5jOyV8HYKOz1Dq5lZonU4dzQKRJ8cBwBZAkZOWOKKRfkZ/EAtYk6O GdPsJOtUC2QtJwAh7+uf9Opfox4LyaWc+rXvebP0PAZhdA2eP1a0czsIqe1nLnYBY3GJ cNSYaqmUFEmbuK5GEi2S6cNNNKgB+bTUEUbVNBYQ9TqtfbpZeEu1gjxW3TlQ4c+7NKH0 yL0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713803870; x=1714408670; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=W/RJrrrs8RwvpYrHG7SbHwPY/r0CKqLeGFzxu6oxqWA=; b=WXSTutFlo3ogH7wICMzhB0SbqsXSx7R9M9y0AC6GUiXADr51QlJCSUdqFl8S07K3T3 BvBJyJyxLtOZ+/q88xmC28Eqr4CoJDOHFxkU9poEeEQPMijhHo1X936V7zR16pve8h3P YpWu4HEHWpP7hVHPYoGm1sVvcL+mXoE/Hy4PLCMG3cRZaAImI1l25VNUm1j8IYIxINsQ 5ymxSQdu+tiu7nIod7uePMAjW2NG6hAEnjx9c2l1fWNnPG3vRz6DVswx2ouk29jNkLwO ue54UZdha35ORAJXYtBejn3YjavkUOwiCZxpZJFocdEjfZhA0KKZMCMvfE6xFai7WsWx HW4A== X-Forwarded-Encrypted: i=1; AJvYcCVN3bamV3kcdj6HmfnC2zUvQUO8cwJJcpVcg8Q3qCQIwMWkrqAEcc8Qx31QucDxedouOFvP/y9of1A5Kb+h7wVoJEt/Eue9m2WQmBcz X-Gm-Message-State: AOJu0YynhLWtrQnzrL2PZJzu9XxrjZF21NNUh67N5otSfWCbMIM//xX7 rVBJd5QNIeASgVXLFh7Erplk+mg9u7zgxpZKacyjRSiOcy64Sn3ensTgIWBfFek= X-Received: by 2002:a05:600c:4689:b0:418:f308:7fa2 with SMTP id p9-20020a05600c468900b00418f3087fa2mr9531927wmo.14.1713803869838; Mon, 22 Apr 2024 09:37:49 -0700 (PDT) Received: from aspen.lan (aztw-34-b2-v4wan-166919-cust780.vm26.cable.virginm.net. [82.37.195.13]) by smtp.gmail.com with ESMTPSA id jp13-20020a05600c558d00b0041a9a6a2bebsm433343wmb.1.2024.04.22.09.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 09:37:49 -0700 (PDT) From: Daniel Thompson Subject: [PATCH v2 0/7] kdb: Refactor and fix bugs in kdb_read() Date: Mon, 22 Apr 2024 17:35:53 +0100 Message-Id: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> 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-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAOmRJmYC/22N0QrCMAxFf2Xk2Upbtik++R8ypG26LiittFKU0 X83DnzzJXBuck9WKD6TL3DqVsi+UqEUGfSuA7eYGLwgZAYtdS97NYhbQHvN3iCP2bhnykJ7o3F 2akBrgYsP3tBrk14m5oUKn723H1V9059u/KerSkhh1dFplEoeRjzfKZqc9ikHmFprHxZbklS1A AAA To: Jason Wessel , Douglas Anderson Cc: kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, Daniel Thompson , Justin Stitt , stable@vger.kernel.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1729; i=daniel.thompson@linaro.org; h=from:subject:message-id; bh=H6lY9kh62C4YQstjcqSOklbN1ZNSivp/MHHRCWngx/g=; b=owEBbQKS/ZANAwAKAXzjJV0594ihAcsmYgBmJpHtkKsfkSXNmY9hGFqe83qhrZ53UoPZO663u 6hQPnNvMfWJAjMEAAEKAB0WIQQvNUFTUPeVarpwrPB84yVdOfeIoQUCZiaR7QAKCRB84yVdOfeI oeekEACbufg6Gh/VvIIcYb0alGNjOAr7Mt/Xh2T+vBP1rKQ59CIlF6jekwGOWqZrLQWxvngMN7r +1H7M9HRBfuW8EHdOtLkncBL+Zc9sO9XlAVbp0tEZA93WzyFrqZuFUqZVGcVP+RKn76blnYgCLE gkJpCWKRBW+N8amQNP6rmLhZjjVpTuv/0QpPKbkNXbxhUZBrFnrsH+8FkSpx8xwmt6MyTqjKZVJ KUynxaIMBXMyjMv81FgnTojX2NAB8NynwrsxCnhfc/LX5KzKIjCDijYP2wfWpT37VBE4rpiI0rZ qrDgjhRPg0DeHPiKdtjIEOgbD+n5HlWU/iKzNFWpytkKyfFES/3O2Vx2RkkwgXQlUOcBlUJ3HkC gUF217AgffkBRamyjOqPYZszjG4BUibaJTbNmeNK3Oz8p4sSI8y3bW+mgg/t0d/bvSt94f3VUQ/ R/7k40vyL2vrEMSks/kE9e3jUSMWtKe/yWKUueWEi9ILZkSYTrPZhO5H5PdMG0EsJ/Fp914tDgf oGRPWvoUXinJrvLaMgbFYVoGoig80vjilbwmvbYlq/qypUMCUFOnreglL3HSexrsHxykbrEDM82 3JzFHDOlReG7Tcn/GMLAzhQ+o19Akf1JEgaGExm6F6Ce5lH8TLcBpmcbTaQSXpdH25RMZ6FLB52 3Kf8+wJ5FwwDsaw== X-Developer-Key: i=daniel.thompson@linaro.org; a=openpgp; fpr=E38BE19861669213F6E2661AA8A4E3BC5B7B28BE Inspired by a patch from [Justin][1] I took a closer look at kdb_read(). Despite Justin's patch being a (correct) one-line manipulation it was a tough patch to review because the surrounding code was hard to read and it looked like there were unfixed problems. This series isn't enough to make kdb_read() beautiful but it does make it shorter, easier to reason about and fixes two buffer overflows and a screen redraw problem! [1]: https://lore.kernel.org/all/20240403-strncpy-kernel-debug-kdb-kdb_io-c-v1-1-7f78a08e9ff4@google.com/ Signed-off-by: Daniel Thompson --- Changes in v2: - No code changes! - I belatedly realized that one of the cleanups actually fixed a buffer overflow so there are changes to Cc: (to add stable@...) and to one of the patch descriptions. - Link to v1: https://lore.kernel.org/r/20240416-kgdb_read_refactor-v1-0-b18c2d01076d@linaro.org --- Daniel Thompson (7): kdb: Fix buffer overflow during tab-complete kdb: Use format-strings rather than '\0' injection in kdb_read() kdb: Fix console handling when editing and tab-completing commands kdb: Merge identical case statements in kdb_read() kdb: Use format-specifiers rather than memset() for padding in kdb_read() kdb: Replace double memcpy() with memmove() in kdb_read() kdb: Simplify management of tmpbuffer in kdb_read() kernel/debug/kdb/kdb_io.c | 133 ++++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 75 deletions(-) --- base-commit: dccce9b8780618986962ba37c373668bcf426866 change-id: 20240415-kgdb_read_refactor-2ea2dfc15dbb Best regards, -- Daniel Thompson