From nobody Tue Feb 10 12:39:45 2026 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 810A11514E3 for ; Mon, 22 Apr 2024 16:37:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803875; cv=none; b=VATtNr4+Snut2FPvQG4ZJUfWfzE3IxHCFPCJcAEPRtoS2LspRzmcREqWVzdLWu/AUkum9f5esEQneNZVH6pn7SpMmMk8aEKDBMrTrYkIfQKY217oR0+vCj954epwtFpWred0pWT/m/7Ql3Bo/TblzqiJuTrUABH39yCAHeR/vTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803875; c=relaxed/simple; bh=RD1vVQLp64mLJfhlSPCd/oxiYJDCACPe4enawcw/m+0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DhwLMpZy/vJ0KwWbdN2p7s9rAbUk2IfaLnz7gWnW4NciX2TFW3egSGW4pEbT3OcijT57rvzHZyWRlXbzjwhgaN5x2Ke5htOH8TE7i+1x94cAFu96EJNN8n7zWgvN0/1gRr0SRl8SPaRp0jWBQibV0LlXY0lYfSzmhvW10OqqMt8= 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=eYqAWoOE; arc=none smtp.client-ip=209.85.128.43 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="eYqAWoOE" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4187c47405aso31127415e9.3 for ; Mon, 22 Apr 2024 09:37:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713803872; x=1714408672; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uLlQJvdv0mXKQuHEFrLRmmeJdLfjSnZqxQsmnOGp71k=; b=eYqAWoOEEUe29EzqieoAMj8GOfdign1nkyU19vbXhHkdPX7XbqFf4pnvZyTpiqZuiL YAf0icfT74qxobJLA+sqzizR/rv5DoD7RU/v0/CCgOeFWkR2+KIOwuDhUEbs/pxlwtgv 5pRhS4hHmcY3gV400Dj3588FnsLp5xLvjl8+p75o9GIrlzZWSP8eOvkCJZ5bmP0/5eaT 063ErSVOj+sLjjMQLkvQavxcQ4HLQlVuA+A7Quxw+WhZ2JyUzbILwJo0ttD2Z6I8mQb7 8x+bXMdrKTle8Ymf8JEmxvbVitmrx/HhRWAgjuqrLQRKq38tbYYYAuDFN/M9Oe6X9q5R 6KiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713803872; x=1714408672; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uLlQJvdv0mXKQuHEFrLRmmeJdLfjSnZqxQsmnOGp71k=; b=sk5fNGvkx7gUVB89+C+xEV4UHsS0v5+svBjM68Qa161IKuAhUSsoNfWGZDeaAhGuUl a5HkTIMVkQvunRi0qWl1bX9w/PrrNMiQc9qDTf36J3hfLdsBrWd8CQCP0Nd2Q3Mvszok dY/ERJm/Vmawghq0Frb/fHtd1JGK2qellFxZlPcaRUiR2TaaMCLO1SlZAG/4ZrPHuMyO Vm6B4x5nTs6twPVMMAYICV1DV2Auun/9VcJ3xRJUdRcMDon7h2LtJBtZJmtB2upqdHyj mc7yeo+UD6eT5Xg61IziQqkTjECziyFc636HQpyWSo5l5riubGk4n6n7WpzBfJLBmY9s F6ag== X-Forwarded-Encrypted: i=1; AJvYcCVBPe+eZuzEEWxYHxfD81DmkJb2dSZt4Jy6zPiPlGA6g1NVf70aohghqfot+abYl0BxHXa9TESCWqA/tzN9Sn+AAuGJBDwhsSEVIYMr X-Gm-Message-State: AOJu0YxkNzgtvzirT/eCkUokgT0d/SEalf0XOiZAXOoW/Jce1rdiCNUB r9M1ET0Yv27hAf4siHQ55LwtZh1op8uaKSN9REP9OoQ1PGSbe74WcB3MA2h7aWYf4nbQFtLcVY1 0FZA= X-Google-Smtp-Source: AGHT+IHHkVv9DQX/lIAuRVXKPDE+plq+CITnqv7QwHnCNH5XAeZdPI7izVuhMSryc6z8ud8SzuL6zw== X-Received: by 2002:a05:600c:a01:b0:41a:2fd9:fc9f with SMTP id z1-20020a05600c0a0100b0041a2fd9fc9fmr3843899wmp.41.1713803871796; Mon, 22 Apr 2024 09:37:51 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 09:37:50 -0700 (PDT) From: Daniel Thompson Date: Mon, 22 Apr 2024 17:35:54 +0100 Subject: [PATCH v2 1/7] kdb: Fix buffer overflow during tab-complete 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: quoted-printable Message-Id: <20240422-kgdb_read_refactor-v2-1-ed51f7d145fe@linaro.org> References: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> In-Reply-To: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> 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=2106; i=daniel.thompson@linaro.org; h=from:subject:message-id; bh=RD1vVQLp64mLJfhlSPCd/oxiYJDCACPe4enawcw/m+0=; b=owEBbQKS/ZANAwAKAXzjJV0594ihAcsmYgBmJpH6kqjNS17dkmKBXEHPrV0RK4mr41OpljOyn f1xQLXv9tuJAjMEAAEKAB0WIQQvNUFTUPeVarpwrPB84yVdOfeIoQUCZiaR+gAKCRB84yVdOfeI oU4pD/9KY2d7fqfBxeIVIKTM7DBkMfKKzyOvuLFcAAvoyUCVc7nzcmUXMIvxo5Lhr5cWaUVIEf1 aw65pCUM0sJzZaXSuhIU//iHoootW9Rk51sVMg2GMtcCazJ1mCl3itLI6bDT3hnhG+ifrnfxCV9 c7LK+Fvii3VzhAJ4B+aStvFDm4PNtKOCA450awbfG95y8AuBL474ZcUbaM+XE7y/JJHFt1OzOsm JfNcRL3bMJ7z4/UM4h5NJRcwGfEHucDLHB+zfJdRG27gxNQCZfcsH8jWdmDvAWfeLPGdGS0hBRJ lyqYqLi1C/jUVzV83DVD8LmPH+YZgdcZFXiSrzi6v5ur2Lxe8OOgq5Xl8hHiY8oXsKwbXuXigsh Zx3KNGS0uxGj65O4Q929ffAVoi4caDLBntCdah0q+rarBuonRLt+NjRZFYmGpf0NO5ely06Hn2t P1BiA6ffo9tfrRO8c5iDs/dcmoeWpEDIZ/Sr0q42Lcs6F0vbOSy8+/4Jhx7vrpbv7DPaPZ6wTZ9 qE3lUqD2tRgS3Y8fjH9bWHvl849maqDqPSbkQHPRQ4eYtoBWGFuNzU0FFN2i/24c25BAmlbnaqZ T+r2VWFvbLClrFTHtYVqFeGMl2NvE3y7Apg/BvBVsGcjUr5FXaHRbmIXOTck7X6FJ+APD6hO8G+ YDpTFf1NnTNpucQ== X-Developer-Key: i=daniel.thompson@linaro.org; a=openpgp; fpr=E38BE19861669213F6E2661AA8A4E3BC5B7B28BE Currently, when the user attempts symbol completion with the Tab key, kdb will use strncpy() to insert the completed symbol into the command buffer. Unfortunately it passes the size of the source buffer rather than the destination to strncpy() with predictably horrible results. Most obviously if the command buffer is already full but cp, the cursor position, is in the middle of the buffer, then we will write past the end of the supplied buffer. Fix this by replacing the dubious strncpy() calls with memmove()/memcpy() calls plus explicit boundary checks to make sure we have enough space before we start moving characters around. Reported-by: Justin Stitt Closes: https://lore.kernel.org/all/CAFhGd8qESuuifuHsNjFPR-Va3P80bxrw+LqvC8= deA8GziUJLpw@mail.gmail.com/ Cc: stable@vger.kernel.org Signed-off-by: Daniel Thompson Reviewed-by: Douglas Anderson Reviewed-by: Justin Stitt Tested-by: Justin Stitt --- kernel/debug/kdb/kdb_io.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 9443bc63c5a24..06dfbccb10336 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -367,14 +367,19 @@ static char *kdb_read(char *buffer, size_t bufsize) kdb_printf(kdb_prompt_str); kdb_printf("%s", buffer); } else if (tab !=3D 2 && count > 0) { - len_tmp =3D strlen(p_tmp); - strncpy(p_tmp+len_tmp, cp, lastchar-cp+1); - len_tmp =3D strlen(p_tmp); - strncpy(cp, p_tmp+len, len_tmp-len + 1); - len =3D len_tmp - len; - kdb_printf("%s", cp); - cp +=3D len; - lastchar +=3D len; + /* How many new characters do we want from tmpbuffer? */ + len_tmp =3D strlen(p_tmp) - len; + if (lastchar + len_tmp >=3D bufend) + len_tmp =3D bufend - lastchar; + + if (len_tmp) { + /* + 1 ensures the '\0' is memmove'd */ + memmove(cp+len_tmp, cp, (lastchar-cp) + 1); + memcpy(cp, p_tmp+len, len_tmp); + kdb_printf("%s", cp); + cp +=3D len_tmp; + lastchar +=3D len_tmp; + } } kdb_nextline =3D 1; /* reset output line number */ break; --=20 2.43.0 From nobody Tue Feb 10 12:39:45 2026 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 F0A24153816 for ; Mon, 22 Apr 2024 16:37:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803875; cv=none; b=QKFrwqsSCfzAABFmbnkRQxA2T0qmqRUi9hPwfyayorg/Up+zwWD3fPe1B5K/U5M1BWssygZh7nszORtSRa4yuQL10fNLDqt3MPTIEghVoF6XdZNK7OaXUmPLlbj9YK/TWQk8UeUbxdm56nfUgTP/rgYpmpNp1dptcsSbqPOq0xE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803875; c=relaxed/simple; bh=/6p73t1vQBs60bTu8b+1GCgEu36ZH+1LONSsLqShnFQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kX6bBG7RcyR7kK2VthLpJt0lOfA8RY2EpyjQ3SgURH4B48+ZH4qQwBJpUuhMjX6TKIG2d1MN2yQAB/EhmQWv18Fcqf+SON2+LTiEp3wPxQhvy6Iyrmk4STLyES9NTktrvGmszQ71IeSTk1Vz3Qz+Jf8PA5h90PxHZQ6lv9g5UE0= 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=eACLT0Gq; arc=none smtp.client-ip=209.85.128.46 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="eACLT0Gq" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-41a74e60753so7239455e9.1 for ; Mon, 22 Apr 2024 09:37:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713803872; x=1714408672; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=P0169n4vHsrlup9ubNFunAJmhMk888VjX3f7O4lXGgA=; b=eACLT0GqEfloYeH+etkMKy3F97+zbiGVwLmlzyV27saPTlv1e2LWNxH/vVpizkqkeL uuDudZiOsXuW2cnap6No9ChALceyjyr4p2xS7Un7nCgn0TAWmX9UynXwP8w5WaiM7paF lrjl6cohCIJqQhBXH674ESVtCE841L1ikuQ0okxCm1sXwOJju0q+SNvNqT8ghxtV19W7 8evXdP2Je6v/4qjyWs97ytHUBsmQoVzUGDoZBQeCv/Mc4Oha7tcxM8HMvnwNc3R5bJfl w/lYHMLCVjXkPqJwlAprPFBnVLegbFrTyL9N2URDD2Hl4wNlqYYB0/983vm8nugPhpUq cwOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713803872; x=1714408672; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P0169n4vHsrlup9ubNFunAJmhMk888VjX3f7O4lXGgA=; b=vqCd0/99Uqvj/S5TrU4pJeU8lBZ3AkLBLXYaDdArABhcOazh8sx132cwy7w1SSwyfH TFs26XVievilqYqEn8o0paO6DVpyihrdH3PtNYj314LvWRUhwW0Z6r5qY/h3Vy3neV/w 7Jnrbq6begnEFb5Z2UV7voMq/lbBlRY7E7A+UbZwm3iVXXAZ7yy3UvytRtNq8tJa/ZqY uQCXnUS9dIlqfxc2P08NDRZtzRn7m9JxWr/d4Jv77/SW4XoA1tiVI43QATiWZcl9M4MP T0W2knP9WDLyMHcob5F8z+H14hdGbaCMBgczbl/hLCJobxFm6n9Re+tclAWMea2SjGMo mRMQ== X-Forwarded-Encrypted: i=1; AJvYcCUaVibFkNCQGfIbR7uIfOJf+fE9Nf5Nm6VgShxXQ/+wKn3N6XbECz2meqg8O/cy0gURcT8wFIvhsCYuZ9h0QUHYP5bncriYFU+xc3Tw X-Gm-Message-State: AOJu0YzjTj4KCwm4vZx6p2c6o/oapvPOqMm7iHlMROPUShk7uhNEoUVx 5Wbbu4OnF6d/pgtDgSz5LZHlFO13Dr8MGJZLXxvL87o8YoRr5e9VEd76nvLTuWU= X-Google-Smtp-Source: AGHT+IFDAAvb8ETo8De2eJqNKoycsShByig8HHkfyzUlmRRzC/jqyTN43Wz55FLnwpcwrQEy/c1YjQ== X-Received: by 2002:a05:600c:3acc:b0:41a:5735:66c8 with SMTP id d12-20020a05600c3acc00b0041a573566c8mr2041049wms.24.1713803872432; Mon, 22 Apr 2024 09:37:52 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 09:37:52 -0700 (PDT) From: Daniel Thompson Date: Mon, 22 Apr 2024 17:35:55 +0100 Subject: [PATCH v2 2/7] kdb: Use format-strings rather than '\0' injection in kdb_read() 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: quoted-printable Message-Id: <20240422-kgdb_read_refactor-v2-2-ed51f7d145fe@linaro.org> References: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> In-Reply-To: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> To: Jason Wessel , Douglas Anderson Cc: kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, Daniel Thompson , stable@vger.kernel.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2732; i=daniel.thompson@linaro.org; h=from:subject:message-id; bh=/6p73t1vQBs60bTu8b+1GCgEu36ZH+1LONSsLqShnFQ=; b=owEBbQKS/ZANAwAKAXzjJV0594ihAcsmYgBmJpIIW3xYkh3ftEnJ/RSyvRs2J+mRuC9iAg4cv Zv/heHfsbCJAjMEAAEKAB0WIQQvNUFTUPeVarpwrPB84yVdOfeIoQUCZiaSCAAKCRB84yVdOfeI oVAsD/9HzAXKmRkN+CwWlgwz8ifB4D9EiWAg0lomCVFYfz20jy6G5Je4ThTVfqFZr8tfx+7UAUc w2pmHbzGWIgWyuzvh3fSTrnjyIj+q6fEISivf/zsypr6pEAtT9E2y7QHz7bbw7fkTQ3OCagZQAt LxMq8PsMxW01ztK1BF6DOuONiy7kWJVxmIwxR9e51yxBVQ76PZAqddoRujmu0anlxNYpOjgQA3w dkv5AVRLwZrAgtaxllo7q+LcjEUYb6HFEsKFxX4jKd556efKst0VcMLuPcCMxmOY6VhP96w3OZV zzMOgQMNwRO4Qu78qQ+cApilvVBgyVbOI76UiD3j85Y6cWxqGVzzrZbWT5boHH/xLg+cs8t6t/a qvDh65H3v2ov3GUHXBx3HvXycJg6NzOPuULhczsUbldC9moHu427hrZRhJqd+VPsiWBpxAsqmnm LAWujzUl5Iz3HhrKUtxJMlpPtf2IXXLfOBvZAby0WI+CpKWJEqJGJHrSxoSuVU/+xWT7cbyQX02 gGYIrQZmOY3UTAUgug3legb+LA/XGyPc9VP1XwOdjU++aAcEyNEts4gkYVr3AQ0YCNMjxAv9khk 9PwvW0NcLLJMxAZMtzBiDgKBE9K8L6svrhdenDqu+6fPbesQ0bIW8ixmo8U3NVD7HAb9xXxnxPF KKNQOUakutckF1w== X-Developer-Key: i=daniel.thompson@linaro.org; a=openpgp; fpr=E38BE19861669213F6E2661AA8A4E3BC5B7B28BE Currently when kdb_read() needs to reposition the cursor it uses copy and paste code that works by injecting an '\0' at the cursor position before delivering a carriage-return and reprinting the line (which stops at the '\0'). Tidy up the code by hoisting the copy and paste code into an appropriately named function. Additionally let's replace the '\0' injection with a proper field width parameter so that the string will be abridged during formatting instead. Cc: stable@vger.kernel.org # Not a bug fix but it is needed for later bug f= ixes Signed-off-by: Daniel Thompson Tested-by: Justin Stitt --- kernel/debug/kdb/kdb_io.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 06dfbccb10336..a42607e4d1aba 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -184,6 +184,13 @@ char kdb_getchar(void) unreachable(); } =20 +static void kdb_position_cursor(char *prompt, char *buffer, char *cp) +{ + kdb_printf("\r%s", kdb_prompt_str); + if (cp > buffer) + kdb_printf("%.*s", (int)(cp - buffer), buffer); +} + /* * kdb_read * @@ -249,12 +256,8 @@ static char *kdb_read(char *buffer, size_t bufsize) } *(--lastchar) =3D '\0'; --cp; - kdb_printf("\b%s \r", cp); - tmp =3D *cp; - *cp =3D '\0'; - kdb_printf(kdb_prompt_str); - kdb_printf("%s", buffer); - *cp =3D tmp; + kdb_printf("\b%s ", cp); + kdb_position_cursor(kdb_prompt_str, buffer, cp); } break; case 10: /* linefeed */ @@ -272,19 +275,14 @@ static char *kdb_read(char *buffer, size_t bufsize) memcpy(tmpbuffer, cp+1, lastchar - cp - 1); memcpy(cp, tmpbuffer, lastchar - cp - 1); *(--lastchar) =3D '\0'; - kdb_printf("%s \r", cp); - tmp =3D *cp; - *cp =3D '\0'; - kdb_printf(kdb_prompt_str); - kdb_printf("%s", buffer); - *cp =3D tmp; + kdb_printf("%s ", cp); + kdb_position_cursor(kdb_prompt_str, buffer, cp); } break; case 1: /* Home */ if (cp > buffer) { - kdb_printf("\r"); - kdb_printf(kdb_prompt_str); cp =3D buffer; + kdb_position_cursor(kdb_prompt_str, buffer, cp); } break; case 5: /* End */ @@ -390,13 +388,9 @@ static char *kdb_read(char *buffer, size_t bufsize) memcpy(cp+1, tmpbuffer, lastchar - cp); *++lastchar =3D '\0'; *cp =3D key; - kdb_printf("%s\r", cp); + kdb_printf("%s", cp); ++cp; - tmp =3D *cp; - *cp =3D '\0'; - kdb_printf(kdb_prompt_str); - kdb_printf("%s", buffer); - *cp =3D tmp; + kdb_position_cursor(kdb_prompt_str, buffer, cp); } else { *++lastchar =3D '\0'; *cp++ =3D key; --=20 2.43.0 From nobody Tue Feb 10 12:39:45 2026 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 444D5153BC3 for ; Mon, 22 Apr 2024 16:37:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803877; cv=none; b=ksrhslvNuL3p+f0ec9kPMX51kUlB1hbil6JJGwQniPDOsZ98bvRbBPXk60A7URRKFz6tM+kxVBENyJiimPnLEu8soYn2Jrjfs8TTpKKR1NucDKZ2SQh0ltPe+MOH/X/XEGmTFmRy35NardwXxhVLKzuMs3uOegUQ3LJ4GeZT62U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803877; c=relaxed/simple; bh=jn1ryZV2lseU9K0OYgA4GJIVFoBB6E4nLhtvlmWlSd4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T/5bVS+kQpVCXiFnmqvAw+BUiu3R7YS0KzmZ1UhrAaq3ra+b5VAdLPraRhWg3c2xrZGAEdT8Mm0GGp4uJlt31kQzmKUucqJ0w8cv77ON31IMvjYT3J/kGNOIY3/GLiuTIf+JCHHPxloNpNLtreLhkAg0FduAZwEAEkUTGqBqgrw= 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=RXBKRerc; arc=none smtp.client-ip=209.85.221.52 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="RXBKRerc" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-3481bb34e7dso2560671f8f.3 for ; Mon, 22 Apr 2024 09:37:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713803875; x=1714408675; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Qw8fuXLn1BipxTXGJjzIm9TXoIt9ndz+hzAX+iGey14=; b=RXBKRerchyjTwFhkxeoqr8K7ZlMetLhLv/hwTU9mlXmQrQe5UgBnj1H+xXgYtyG8qh Xi5+wpMpgUQaW59ugmNTDa9mmd809sQDilwGSx++Mmt59QACNDP+7GJAhl6nAAvYyQnx n5y2WHYrqK+RNNtGaga0Ydd7+MvgFxJlwDrbhn/kHgq7w6f1zTskbmFFD8ZAy4kZooTw Coj4ixYomACwXbe4PcUUc5Umq6JXK/kJ2hgEE1fvakLHt+6UDjIE6IgoSCj+1xL7WJBz offfkieT9djyi7yn96r4Fr0oe92sW2cW5b26ZGtwaC7IlRHgAiKlIw3o0cSVWC/lNlCq KFWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713803875; x=1714408675; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Qw8fuXLn1BipxTXGJjzIm9TXoIt9ndz+hzAX+iGey14=; b=BvAUFUZkFp6YJu/gOAb7avQaezN3681KujfXYgezs9I4GB4C5CxcEs7EzL8dAaP7q6 lqSLnMFXh6w3HNNHzhErkPMtbOCu3z5VTi48SnVQaTovmv4gXBaJxjudUR3cDgTzZVMj Tc48alB/+R1JzzM2JPWLrPj1Fs/RLqbrj2+pebQCa+Gyi1twAZ5RM4VoDgE5GFKaLESA aEINzPw7TbOfj9ZQjudFlQ9Xz45AUX2aal5UaHVOZXfCqC/VXRUOFs93zNyl49OC1oM/ xjs6RYQB/QgBPoRK1QifTMSio7uodJKvfnYTjB6uSP221C3AP4cuAXMSYxHJ0gJbrK0r uBmw== X-Forwarded-Encrypted: i=1; AJvYcCVKlwzlRZm9zVqEya9KWNgRqzti/NLI+M0E5g/A4NT2Qg5dnw5bvCQ6z36+6l4PeqrBNm9VYGnlIwAZEQMrfsDkDqiFTunomMgNmHTO X-Gm-Message-State: AOJu0Yx3lUP9KhMHa9FiDArFT2OIEh1AZkucQpABkZVN1EWq9BkHrbJB GfsDDY/JQUht0w5hnrGqUg5b2EuzNEjfqz72oFDifmWdVD0digMu+jsRwGrOKOM= X-Google-Smtp-Source: AGHT+IGryKOg26pY9YVtF/etPlBEZSaLETo3yB57+/SrqCekYX9SP+Epj5P1Hph73oDDUhm2wLh4Hw== X-Received: by 2002:a5d:64a6:0:b0:34a:65c8:7413 with SMTP id m6-20020a5d64a6000000b0034a65c87413mr8526451wrp.30.1713803874749; Mon, 22 Apr 2024 09:37:54 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 09:37:52 -0700 (PDT) From: Daniel Thompson Date: Mon, 22 Apr 2024 17:35:56 +0100 Subject: [PATCH v2 3/7] kdb: Fix console handling when editing and tab-completing commands 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: quoted-printable Message-Id: <20240422-kgdb_read_refactor-v2-3-ed51f7d145fe@linaro.org> References: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> In-Reply-To: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> To: Jason Wessel , Douglas Anderson Cc: kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, Daniel Thompson , stable@vger.kernel.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1753; i=daniel.thompson@linaro.org; h=from:subject:message-id; bh=jn1ryZV2lseU9K0OYgA4GJIVFoBB6E4nLhtvlmWlSd4=; b=owEBbQKS/ZANAwAKAXzjJV0594ihAcsmYgBmJpIWu4GpGHzCm/ReOjDS8WmJ0VBKNsUqlRj8p PvT0hB7oC+JAjMEAAEKAB0WIQQvNUFTUPeVarpwrPB84yVdOfeIoQUCZiaSFgAKCRB84yVdOfeI ofrMD/9Dd6x3qx/aTRlgNTpZTqArAi2poVMKGjmG1834eWva0RZweTx6WYLiH/wrJLRc/6MTaQQ GhwXARUTJTzkBwkwnmgaBn5FdQfVm+yqqyykDjkmt8GKErzPLMmO3mor1EOyvjHvuZoxNxFa9A0 H2o30hkW0G2ceopv+UIbjciCydcesR0BvQ77g4kDKQw5rt3M3uX3VWWziTfHT5HKjKRQgBjxEfF VqPpU9WJOCxGSI+43KB1lIG9Jmx2dibWlwMAFHRsOHuHuiSaF0Mu1tiPZrbloa0Wg6qR2BP5BpC EWpTcjJCMMS1onNpc6ocPHKxu74mw9I5R5+PfgXCBcr4VThKk0RBc2yBLedKOTMo1umwnytbmso cU00codNlahOf7pqzLNVuVvgWzYV1Efexu3sMSUenMxAgulb79Zg54aiPphOCRy8jmKSAYdy7uH YahNZ1BgELG2BuoX+UcGME7b3LJ76/9Tysb9vndVo/tQy9Aly48cpIUC8zMIbikLDKxx/cuuVoJ KKosrrN82soM72sdCEW7cq5zgWnjGICCzTSk20y8dl+hXyoMPPip7CoKGDOnqkUHpu6zh2HswFR Wt1DG4BqESNKBG8dD8do6KHmjwdfFFTUfcmrQBTTwhzNgnVAqoU/RsygQuHcfCpsX2lr+0xZWxs SgCt+E5vAk70OSA== X-Developer-Key: i=daniel.thompson@linaro.org; a=openpgp; fpr=E38BE19861669213F6E2661AA8A4E3BC5B7B28BE Currently, if the cursor position is not at the end of the command buffer and the user uses the Tab-complete functions, then the console does not leave the cursor in the correct position. For example consider the following buffer with the cursor positioned at the ^: md kdb_pro 10 ^ Pressing tab should result in: md kdb_prompt_str 10 ^ However this does not happen. Instead the cursor is placed at the end (after then 10) and further cursor movement redraws incorrectly. The same problem exists when we double-Tab but in a different part of the code. Fix this by sending a carriage return and then redisplaying the text to the left of the cursor. Cc: stable@vger.kernel.org Signed-off-by: Daniel Thompson Reviewed-by: Douglas Anderson Tested-by: Justin Stitt --- kernel/debug/kdb/kdb_io.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index a42607e4d1aba..69549fe42e87b 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -364,6 +364,8 @@ static char *kdb_read(char *buffer, size_t bufsize) kdb_printf("\n"); kdb_printf(kdb_prompt_str); kdb_printf("%s", buffer); + if (cp !=3D lastchar) + kdb_position_cursor(kdb_prompt_str, buffer, cp); } else if (tab !=3D 2 && count > 0) { /* How many new characters do we want from tmpbuffer? */ len_tmp =3D strlen(p_tmp) - len; @@ -377,6 +379,9 @@ static char *kdb_read(char *buffer, size_t bufsize) kdb_printf("%s", cp); cp +=3D len_tmp; lastchar +=3D len_tmp; + if (cp !=3D lastchar) + kdb_position_cursor(kdb_prompt_str, + buffer, cp); } } kdb_nextline =3D 1; /* reset output line number */ --=20 2.43.0 From nobody Tue Feb 10 12:39:45 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 21481153BF9 for ; Mon, 22 Apr 2024 16:37:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803880; cv=none; b=TIeqCopigsRE7j0we8l+YZoE+8l5Dn+eDYsjTEBCTcFjXBNY6k+MRP5Bw9ImXD96QE9jDcU4npox5n3UI3s41iOQ8aN9bv0AtPv4zuxNyb8B+IXDGYjvDmxjHI1nsUab+juguSjW6pqLydQ9qojt6Vm9UnVnxRmyItvnPQhjTVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803880; c=relaxed/simple; bh=6LfmSdx/1tWhrPN9tMn/IBWgdpfapqTqrf1F8jgiXeI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Gqu9aYVOA+PewU9AEA9miHDG/TKrj3nGo/MmJ5EFjyqhL0IgnHUNfrGgttYZrtug7L8mqj3C8O3dQtkmx+bUT2uQ8baoQ5xXBSuIGrXN/7EzPHgsacAi5ZPs2QPbFRIqC2kN0n4NcvJSiAzddh05yWHvyvvM6NLgsG6FzYf7aHM= 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=AHfxEBFA; arc=none smtp.client-ip=209.85.128.45 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="AHfxEBFA" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-41a55be31dfso8788085e9.0 for ; Mon, 22 Apr 2024 09:37:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713803876; x=1714408676; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Nk5QmCkWRIrgsvRQxugPUqs3aSht8TynNH4Q3EEiYLA=; b=AHfxEBFAq4hzwPz1UNg949kQyrF0CuN6WlCaK+VlP1J8ES1RYf3vaEunvdTxjX/MX0 MhASTXwYTh68UbissuX3I9CeE1ZHKB2J/k9/MKtljPr7HoxBWL7QRkjfdZjDkEH+z4w7 kEvH35C7kZEyEWvI3RGw/iE4i12cSIh6/tqLg213QaYnBdiBxURqn4XiFbrZgeZPM0h8 ec+YaFAPgv/SxVHe4Sw1ChJ32PsqrYskxVztbOSjuuDIkB4vjwYHO5sKPpjyDKA+AVr7 PUVlMvQvod3wOi8aWQwlQPclU2/BiJsAIVmT51MR2Knng6CKmBR7ok1T20E8jOPbEXtv 9TvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713803876; x=1714408676; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Nk5QmCkWRIrgsvRQxugPUqs3aSht8TynNH4Q3EEiYLA=; b=wxGKNHeWh1brxvf+YmJ+e3BeNIEJnsqoRp88moEXV5MX1Pt10K2ZVx/ASu6yfjJCv0 ceqYm8W3/aCdLjobObnb6D8kdZ+YCoa9xq/+bvfJc1fj48zi8txy1NeFvFJgNBzgZLyf gaR6ZcRoXeDjVIywbvuoOKzEos7F38jS9gj8rHumz5xWhcoilYVUgKwiCeshqm5BWtjp 5ADdwETNPh5oycqcq42CRADvXdSspAwTgXBxrL3+zyBKA7K5MlwxYH/W9MDWDsjhgGPj o6F4sJ5SCQ3ok3vBhUDM5cddUaV8SAZXp1AP0FFpytCCL+nmbVGLpF1j4z8aHJiJon7g JnCw== X-Forwarded-Encrypted: i=1; AJvYcCWtxLsTTBCOHr9Y8hx5xCf6fVbcF9JJv4a4SuLeycSQwLJ5SimbmD3Om730oHuujtM4183P8Set9Rw7ikvyh/YCiggaCb45T9WaX7zJ X-Gm-Message-State: AOJu0YwLnIm4wXfKZtoBG3G1amCdfOdlPTlAFqQl3ucU9lfhKnw90DeE AnuGpjpIlqFzvw+DgKR3iC49se10QBdMsa2QdImxlyvVgoUl2x3TXBVb0F1k3wnaOx6gSvcnjLk 7TbY= X-Google-Smtp-Source: AGHT+IGdbZ8ROPEXmCAeRFFCE1IlKVnfn0ElcoTrib1PzzWJrx4X84g23yKrGfh1exX8j/noBOsw+Q== X-Received: by 2002:a05:600c:4508:b0:418:95a1:1975 with SMTP id t8-20020a05600c450800b0041895a11975mr7465378wmo.20.1713803876595; Mon, 22 Apr 2024 09:37:56 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 09:37:55 -0700 (PDT) From: Daniel Thompson Date: Mon, 22 Apr 2024 17:35:57 +0100 Subject: [PATCH v2 4/7] kdb: Merge identical case statements in kdb_read() 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: quoted-printable Message-Id: <20240422-kgdb_read_refactor-v2-4-ed51f7d145fe@linaro.org> References: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> In-Reply-To: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> To: Jason Wessel , Douglas Anderson Cc: kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, Daniel Thompson , stable@vger.kernel.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1269; i=daniel.thompson@linaro.org; h=from:subject:message-id; bh=6LfmSdx/1tWhrPN9tMn/IBWgdpfapqTqrf1F8jgiXeI=; b=owEBbQKS/ZANAwAKAXzjJV0594ihAcsmYgBmJpIkax3nnA8BhAmdwQ+q1JJXdXciyaK0wRTdp ze988FFBCSJAjMEAAEKAB0WIQQvNUFTUPeVarpwrPB84yVdOfeIoQUCZiaSJAAKCRB84yVdOfeI oR5fEAClOzm3rSzOJIWjtF0ie6Zo4S6K2VgsbsQjG1WYduTN0xhNl8G86G3XNOCAmkJ7AKx2ZMW 812W94SHSmJhU3wdvG9Ntr9TV3MBRsyLsxysGx0ybN3lzrzkL9MqdEKvg4ggwJ0Aiof+k/39wam xKydldkAjYsz7a+2DggOpZKP81AX+E0FERXmwOac3VKvpZfpYszCIqcOEV6U+ImwMeGgnM0Cyef xA4uNDcbmnqgOhbOoENorBYREX5cJf5uanSD0NSl5gCHTiAlLZf4DVC+cDFvss4XpNoKu1YmulQ SPFgFT6TI/ml4YX52jcsiIY//G5prGPg6TC4SIL98ivTCMHN0VaYDWfLoXCb4ScMctSjYs4SNPS bOZbKCJcjj4B5W4AjFaHhHWTMn/0cJlBunXUTgnON0xoA64565OeRMtX4bBrBEpTlnT+EE67f9n mP7xzNYfRL5I4nYyMDCTePpaXfGai+LTQCeM/fFUIuDxD8PweAvQlYJd0Glp0vygcKbTA7pqDuw UvS5kUcZ6p2XZ9ovgZQVApXUT0JtAmKOUBlbQdJN6Zc/GZ0fm9Q02b+2oSAMC7pWPmtnrTxbwBH 2EMMW5g0z5lfdGROq83V6O0H75DAQi13UlIxjCWO5VoGJyr9XQCf1+oir+bpHE0VoFQ1sNNBEj2 pI39upZA9fQFO5A== X-Developer-Key: i=daniel.thompson@linaro.org; a=openpgp; fpr=E38BE19861669213F6E2661AA8A4E3BC5B7B28BE The code that handles case 14 (down) and case 16 (up) has been copy and pasted despite being byte-for-byte identical. Combine them. Cc: stable@vger.kernel.org # Not a bug fix but it is needed for later bug f= ixes Signed-off-by: Daniel Thompson Reviewed-by: Douglas Anderson Tested-by: Justin Stitt --- kernel/debug/kdb/kdb_io.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 69549fe42e87b..f167894b11b8e 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -298,6 +298,7 @@ static char *kdb_read(char *buffer, size_t bufsize) } break; case 14: /* Down */ + case 16: /* Up */ memset(tmpbuffer, ' ', strlen(kdb_prompt_str) + (lastchar-buffer)); *(tmpbuffer+strlen(kdb_prompt_str) + @@ -312,15 +313,6 @@ static char *kdb_read(char *buffer, size_t bufsize) ++cp; } break; - case 16: /* Up */ - memset(tmpbuffer, ' ', - strlen(kdb_prompt_str) + (lastchar-buffer)); - *(tmpbuffer+strlen(kdb_prompt_str) + - (lastchar-buffer)) =3D '\0'; - kdb_printf("\r%s\r", tmpbuffer); - *lastchar =3D (char)key; - *(lastchar+1) =3D '\0'; - return lastchar; case 9: /* Tab */ if (tab < 2) ++tab; --=20 2.43.0 From nobody Tue Feb 10 12:39:45 2026 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 519D315381D for ; Mon, 22 Apr 2024 16:38:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803882; cv=none; b=DdHCb1iEOOZhNQktUSbWO0dgCGZHOCb50GOMIwQcG0F689/VP16EO7+GGb5xP8zaNEVM5WfiZx8KYWp+G1WcXrVkoB5gR3YR7cG5WyrC91vG3dDwkeouA242HnVciYiGbaW1X6oBgfNCFSVybq2UGWn6JblDvZD+j1MHo3V16wA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803882; c=relaxed/simple; bh=EKbL46mJOaKEQMG7PnN0H6MYhOBkih3jmYcm08ayvmY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fHC3YMtKs0mRMU5xX2Dni7Nbpo9GEFsTIuR9+C6FpxI+MCy2YW1TvQ0uLXDIJROHkHM5rXAV+YUD0p3my+NhNd4BGNVGYNXlM9HA/pLFCbw3QMExbw0qiNdRvbrkGtj3tLS/PFwZLmo7K0bOxpaaaeB5X9+avRPf7lGX90sooZE= 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=b5St/K84; arc=none smtp.client-ip=209.85.128.53 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="b5St/K84" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4196c62bb4eso22226995e9.2 for ; Mon, 22 Apr 2024 09:38:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713803879; x=1714408679; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=IaPzC1YdTbbmXVhdYLzIcA/Ug78Q+VkMF3OmhCOncvQ=; b=b5St/K847dFrkjjE7Q98iTlOeWDun6tiMDDvmC8kvGFHZaZV/HwYxCkaS/oUvB/dzc X42mnyFdTcrlW0U/84oJLz/OkLTODRwtHfIS4BoZtVZiLD3CS1dVUutcXM1ThyYFuy+F 51YGZ43MBHMJrj/QEB861FcypHMhp+9/PC1e7a4uM297t7jmcjknlTGWMGZP5MyN7u1i nxPPpp0ciFxkRE8sstpmHm5Ef+gwr8JXlcY6jMYZBi6r9LiYe4zzcvXF3zKL+qFkIuT2 Ggnrlc5nSHoCUFKmz3YmxsMlEIglcSQxJ3P1BQ5XJJ4w18CRLhZfTWYgJZyA1Vm58/fH bZ8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713803879; x=1714408679; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IaPzC1YdTbbmXVhdYLzIcA/Ug78Q+VkMF3OmhCOncvQ=; b=EAAA1dWHgA0QicYpRCHch0STakpLQndwFr0qRJb0oQRPVRdhqoNzR62lYBRn2sPXGB 6e3EmPp/Y9Qn3a/mtbvAhtdPDbYIiCLfaJK58WSaODE2kzMFOQZDfJwcWSmX52UO7bsl NfyhvRXguxJDV7Xru2T1Hsgi+zs7oGE3aj5pKxGe6dakJk2etojJ3NYxAFVCt5ZfYiVj iL58oq5Z7i/YM6a+W2Sf0A5y9+XEhdV1bYzoUg4eeD5/IhrO9KAtOuZ5fZih5/Y2SQ5N ao3l7NL3u1sTFp3L2WX39oZPSDPtDx8qSyPDK77GXvb1i8Hn3QQIY+Nxt7ElreCRdFVU xFVA== X-Forwarded-Encrypted: i=1; AJvYcCVY3bGsS49yuEWHRK1JBi/jWWMGU4sLW+BxXxN0fWtXCtgzNURWrhCjuIskY8VaDwgjyB6DCYBXV/HCfxw7gzCeB4pQwIzGUmHsKQy7 X-Gm-Message-State: AOJu0YwsJjKSY7f6TJV93aB9Xa8XMI4YzDaWIwSqxU+uZ+OoELOlDAtr 4NwQeADH6rN0zsTZxPZK8rVxEaJgTbW0Z5k4oktEy2i1WORCN4bFSOVJjx1YRws= X-Google-Smtp-Source: AGHT+IHIey51AWtx4VQyISLIZOC+vyssMRjF9SgVnb/8KezLsfOHB0E7atrtdgz2hjexSrkqhw1I3w== X-Received: by 2002:a05:600c:524e:b0:418:fc73:c0d3 with SMTP id fc14-20020a05600c524e00b00418fc73c0d3mr7093929wmb.24.1713803878838; Mon, 22 Apr 2024 09:37:58 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 09:37:57 -0700 (PDT) From: Daniel Thompson Date: Mon, 22 Apr 2024 17:35:58 +0100 Subject: [PATCH v2 5/7] kdb: Use format-specifiers rather than memset() for padding in kdb_read() 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: quoted-printable Message-Id: <20240422-kgdb_read_refactor-v2-5-ed51f7d145fe@linaro.org> References: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> In-Reply-To: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> To: Jason Wessel , Douglas Anderson Cc: kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, Daniel Thompson , stable@vger.kernel.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1348; i=daniel.thompson@linaro.org; h=from:subject:message-id; bh=EKbL46mJOaKEQMG7PnN0H6MYhOBkih3jmYcm08ayvmY=; b=owEBbQKS/ZANAwAKAXzjJV0594ihAcsmYgBmJpIzc+qxB+38dGrvf11xB/JwP24/5iyxfzXnR 7S9uLz9qIaJAjMEAAEKAB0WIQQvNUFTUPeVarpwrPB84yVdOfeIoQUCZiaSMwAKCRB84yVdOfeI oaVID/0VfTx+yaeruOa+2ykO35gx+u7NUo2WoPk0OF4mLglbzFwFCAFYEixVj0oZa2Qrvxi/7Zl Vg/X68oSztt6j/GiPZ28PTMgUH2F8CBg76ByY3EkKJRk+II13lqZXKldZV9vujuFr77rGBrnFfQ BwS3BEv4ne5B1QSbb572bByM6z8ir/cT0bC6b5231gZkxnh51sIEQxt+7ZvbOq33xsAaU4Z6xkK 83Nrt5ayJuolqgwtyuoFdPJB6u+ybUojj7MNE5Cd+x0zqRDtq4WYDPsbJzIG1ZVAjYDDULJnEom lCuxbBcTfbJtqtacC35zqD7XqcqLjtJBpvN/3Zj+I3ZbzsX6X3oSe6EdLm4uusxjKM0HXu+09Yz 1Gh0TwxPbaMvOrD3cijWo6CtGNXe5xLCnIgn3CvMHq6OpbcoZtQeM/L1Bd3UQnHh7O7mULCai+N fO7rrFexjVMwXnPAkeBA9+3pDbe5dITuKEwNSVBCqHhsfm47I0Q+w/5MzmUntEh+mbmFksyNxCy 34Aouq8LuayIGXynacVyDo1ORQ+YtyNyvwczP3zoTyFZo0pA7SszISNFTbPlzjU8k411CDYrTSW abYYUkMtPLM+TpNDxSrc8cb0U1bMVoGbo0PmPdOe8BPY1z6qasGJ6OSesjBergm3AiLEOV1FL+s BnSw0TsuHftAgzA== X-Developer-Key: i=daniel.thompson@linaro.org; a=openpgp; fpr=E38BE19861669213F6E2661AA8A4E3BC5B7B28BE Currently when the current line should be removed from the display kdb_read() uses memset() to fill a temporary buffer with spaces. The problem is not that this could be trivially implemented using a format string rather than open coding it. The real problem is that it is possible, on systems with a long kdb_prompt_str, to write pas the end of the tmpbuffer. Happily, as mentioned above, this can be trivially implemented using a format string. Make it so! Cc: stable@vger.kernel.org Signed-off-by: Daniel Thompson Reviewed-by: Douglas Anderson Tested-by: Justin Stitt --- kernel/debug/kdb/kdb_io.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index f167894b11b8e..2cd17313fe652 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -299,11 +299,9 @@ static char *kdb_read(char *buffer, size_t bufsize) break; case 14: /* Down */ case 16: /* Up */ - memset(tmpbuffer, ' ', - strlen(kdb_prompt_str) + (lastchar-buffer)); - *(tmpbuffer+strlen(kdb_prompt_str) + - (lastchar-buffer)) =3D '\0'; - kdb_printf("\r%s\r", tmpbuffer); + kdb_printf("\r%*c\r", + (int)(strlen(kdb_prompt_str) + (lastchar - buffer)), + ' '); *lastchar =3D (char)key; *(lastchar+1) =3D '\0'; return lastchar; --=20 2.43.0 From nobody Tue Feb 10 12:39:45 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 3E1C415444B for ; Mon, 22 Apr 2024 16:38:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803882; cv=none; b=HXpYpD8n0Fm/mulVRqpdLxuwWZLWbdY2D4E0RZ4wEeawd7267IFAlkb2Pp/4bs5gjPyenR+fHkJECEmG8YY4Wn09cMn1XIVp8iZf3Z3nsv6vxPED0xPVRAWH3SHBbSTOmmJu8ovf7AYaHikRH+dw5S1TJ2p90CrIZ66rXIJeqp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803882; c=relaxed/simple; bh=9ajOnuk8c/3dgVcp4I+/1t4zbyy/pCAdQ2SjxrxY5/0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HOTgdJUkmJN3Es/BWdyJfRpHF+FP+bLbu0XeYf5wYewcO7wQp1ug1JrXpQjyXj8XFH2x6Tw41sa0tcRjbALM4k7VPkK8IG2nBSnZAQvLveBzw9wP7dhRngqK7IoiJ6aVGwSFnyqz88iSxkUWEq6MoBds7iCmx/x2JAVfBkb6UJA= 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=emX9lxJ3; arc=none smtp.client-ip=209.85.128.45 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="emX9lxJ3" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-41a55be31eeso9338405e9.0 for ; Mon, 22 Apr 2024 09:38:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713803879; x=1714408679; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=qZGZDEe7fnoZT93Svr7Nmn3u9YXAd7uDjSZyL4bPcxE=; b=emX9lxJ39rNkRWo0dBjicYwtlfLh2czHRU4K+TCbGuTdOnyWdB/iM34oGm3sxsKCOC 7K3/PYU1BAr+3fvbRDq8zU0uYd9qHQbVTYvbFoF2laSQKQtaYKqN0sIeLX6vfoCgPQNm qZk2y5Zi4ZFn2FjT0bsbY18RCoNJ8nRDIMsm16VQxLIYr+Fs8qMDZlkYU5yOztoR+TFU 55TjRFXsPIW/UuClNPU3Afu8deuuBQtTbxfucixmL38a/6vKTvjfmpRdm7FRncQj+ls0 SoPC/EH0jZ7fu0hP4qfnsvz+GGoXW534hcIX/4ySa28X6JIsiHEUrvcuDQzf42ZfKDPx WSkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713803879; x=1714408679; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qZGZDEe7fnoZT93Svr7Nmn3u9YXAd7uDjSZyL4bPcxE=; b=CIAGRgVwULDrSU4iqQypEkygELFIgJLako5SaFQ8nDiEStX9PR1NrfRxVaXpcLP7dr Y61k3fika2FNzsIMmA5CeOCYnp9P7iUTWatREkFdES70Q2zUI8kBVSkY3NJfR8Ay/YoI inyKE9V9vbZGQ0AEXZoRaMqDL96Q0d9bu1iYmInAmEvIUsunXkwhxAtgGgipvCHo06BU 5KFQPaMy3i9uPjKF1rk5WRq31IUx+b8wjKGzz9iNJMR04W9HWSeGaMadtzzdUK2mkebf Kz4vS/B+Vxr6JBaBtcPuJBwikpd6mm061S48xrKHzG84nX5d1a4zulPYHfQMbkWLJpx8 dung== X-Forwarded-Encrypted: i=1; AJvYcCXGBc9qGgJfv2V8vePgcBTLluGw93u1w6pfPQ08MO3sU64QNFEgMOYnzTQ2MmUZIUJUq2kz4hvUO+1pwIYFpE/7xBiR1R/nIh9IImvF X-Gm-Message-State: AOJu0YycHCnFksJqjqzJn5aPfkezro90OUdkFGLSQVww2If96EjlKRge 8IlJPhi2qfE71v55N0fKN0749RjVl/jIn2k3YqFN4WYbe8p8PeVwk7mReanm03I= X-Google-Smtp-Source: AGHT+IEXFlj5GoEouTne/NUIpKd2uLL5aHsKuorpOmx9f/agwxML5PNLpBAAwQO4eBdFAX6Ve1ICPA== X-Received: by 2002:a05:600c:5494:b0:419:f3fa:2434 with SMTP id iv20-20020a05600c549400b00419f3fa2434mr6943703wmb.41.1713803879635; Mon, 22 Apr 2024 09:37:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 09:37:59 -0700 (PDT) From: Daniel Thompson Date: Mon, 22 Apr 2024 17:35:59 +0100 Subject: [PATCH v2 6/7] kdb: Replace double memcpy() with memmove() in kdb_read() 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: quoted-printable Message-Id: <20240422-kgdb_read_refactor-v2-6-ed51f7d145fe@linaro.org> References: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> In-Reply-To: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> To: Jason Wessel , Douglas Anderson Cc: kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, Daniel Thompson X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2359; i=daniel.thompson@linaro.org; h=from:subject:message-id; bh=9ajOnuk8c/3dgVcp4I+/1t4zbyy/pCAdQ2SjxrxY5/0=; b=owEBbQKS/ZANAwAKAXzjJV0594ihAcsmYgBmJpJAFzVzaduRhdf4iIyVREZ7MeHvob4Xtd3BR 7GLT8ka0sCJAjMEAAEKAB0WIQQvNUFTUPeVarpwrPB84yVdOfeIoQUCZiaSQAAKCRB84yVdOfeI oV/xEACkDdfOdizY/ztkA6mJARyXym2GSv1nS5yuuEP/cL81L4tENqnRSKTI+rb1LKJssvmXr8P OYC9wXUPSnT0RCCROUvEvpHHHbGueO3I3x4HN09nah+m2TVhpFn6Hykd9Hg/OJs7EXGNAW9kGm5 zCprCSbbvDnD0Mv+OmPZBwhpmNAo134OF0YNFtme8+ehwe4YriCnmXzgojF6RRZkF50N2PeRlPT ErkzwY60/w3Z+u36HFkzYmh/tnD77nu9mX1V6KaWFRzUF+XVlvKHGknU+dAzAK0LD+CrRW5iTq5 pbxzbdbG7nYYPNuv+GkcrS4d+nZQLPU4OMChSYWUUpp61W1I0h2iuVi6e2dTYydydwjQ5E07Pgk INdMo/EJuTWd/+JTrvA5q0O8UI1lg1uJ1FagxC4flnss9VW6dkTnR+yeqWzQg1Y3eXE7ZmtOP8o uEIu7heYRsvliWkRVL5uXMlxJPF0MXDYKkSiNrvLzwoJlb3a/scjQdJdj67VrAM+Mo6Qfgbrd4P 6/PRuwJ1+i6vRNThJz2xVYpLJq7K+/aWCr9XARKzTYK0DKlvdxN6WFVIQsDOMNs0Mc6zEILDgzk GSNdTmalIqQwZ79BhC925qohq6GCShPRSpA1svvKE+EmT/lwBKiQZy3ce0qizq+8ZjC3I3QlyCK lcSErY+3tmPgE4A== X-Developer-Key: i=daniel.thompson@linaro.org; a=openpgp; fpr=E38BE19861669213F6E2661AA8A4E3BC5B7B28BE At several points in kdb_read() there are variants of the following code pattern (with offsets slightly altered): memcpy(tmpbuffer, cp, lastchar - cp); memcpy(cp-1, tmpbuffer, lastchar - cp); *(--lastchar) =3D '\0'; There is no need to use tmpbuffer here, since we can use memmove() instead so refactor in the obvious way. Additionally the strings that are being copied are already properly terminated so let's also change the code so that the library calls also move the terminator. Changing how the terminators are managed has no functional effect for now but might allow us to retire lastchar at a later point. lastchar, although stored as a pointer, is functionally equivalent to caching strlen(buffer). Signed-off-by: Daniel Thompson Reviewed-by: Douglas Anderson Tested-by: Justin Stitt --- kernel/debug/kdb/kdb_io.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 2cd17313fe652..94a638a9d52fa 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -250,12 +250,9 @@ static char *kdb_read(char *buffer, size_t bufsize) switch (key) { case 8: /* backspace */ if (cp > buffer) { - if (cp < lastchar) { - memcpy(tmpbuffer, cp, lastchar - cp); - memcpy(cp-1, tmpbuffer, lastchar - cp); - } - *(--lastchar) =3D '\0'; - --cp; + memmove(cp-1, cp, lastchar - cp + 1); + lastchar--; + cp--; kdb_printf("\b%s ", cp); kdb_position_cursor(kdb_prompt_str, buffer, cp); } @@ -272,9 +269,8 @@ static char *kdb_read(char *buffer, size_t bufsize) return buffer; case 4: /* Del */ if (cp < lastchar) { - memcpy(tmpbuffer, cp+1, lastchar - cp - 1); - memcpy(cp, tmpbuffer, lastchar - cp - 1); - *(--lastchar) =3D '\0'; + memmove(cp, cp+1, lastchar - cp); + lastchar--; kdb_printf("%s ", cp); kdb_position_cursor(kdb_prompt_str, buffer, cp); } @@ -379,9 +375,8 @@ static char *kdb_read(char *buffer, size_t bufsize) default: if (key >=3D 32 && lastchar < bufend) { if (cp < lastchar) { - memcpy(tmpbuffer, cp, lastchar - cp); - memcpy(cp+1, tmpbuffer, lastchar - cp); - *++lastchar =3D '\0'; + memmove(cp+1, cp, lastchar - cp + 1); + lastchar++; *cp =3D key; kdb_printf("%s", cp); ++cp; --=20 2.43.0 From nobody Tue Feb 10 12:39:45 2026 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 D3CDC154BE3 for ; Mon, 22 Apr 2024 16:38:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803884; cv=none; b=WMozckFNcyX3BoXgbL76CtdOjGls/WKXcglbVe+8/u7x27Dlnvrl0e3qtTx1fW7Vo3+gvLtwYn9HWNalNTaDv4OAqiLOY2yAsULv1mkXv/2H77NO8ARk4TjPsK2o63l0V7cZbv6zZL+qaBucRTa65iKv3fTeuseL5bSmaNDEyO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803884; c=relaxed/simple; bh=d2qYpbUEJ3bo57WTysC1k9+78U0fLX5bGNTDzJBq7DU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uVn/C0y3i2dUAZK25HONvywtWrCfx0rob3u1s1k7seNfeF+ROt8GJrW3K7v92oXI/bYG5KeuvzQIr+PahzIMIyigUdFeTTc1JxcTw0W+mfFLKKvmzWlkfIHUkINMo9ltGvGpycn4gUeayYZ/wxHtWX1OgC7qd7X1014j4qNaZjo= 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=j2pcpYlO; arc=none smtp.client-ip=209.85.221.53 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="j2pcpYlO" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-345b857d7adso3654733f8f.1 for ; Mon, 22 Apr 2024 09:38:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713803881; x=1714408681; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=qax0/HGbPdCX4M7gDaYwDwDlZ1cE1xlWdr0Di9/Hmb0=; b=j2pcpYlOuSilrEE69yarnMHi8RKDx811Cc309uXq1ZnBitG9uTIMGb70RBV2iU3CfN 5K6Q1yK57TqmD4jxlKtBfm1fZqQqRJOqSxJg0w0TkUYDA13QDQt9drRJ6nbZiSRmA/Ps 2BbPOPZjayteo/gpfdQNC7G1Rda5oJKeB+mizzlcz4gbDTPxMduKXTw/9OKhj+9e/c8D mjhzQk8m+h6F3Mw+pdClP9eYEcU0Y0BWS27l4xBM2pHMUqw++9xwi5Nuc7N4F6W6lhjl Q8X9HL7M6ZRJ1i7bAIL3BF+uZQXsHuOEOMVhildVxEh5RqPOCWjjaJ23uzr/zTeL7eiA 9u8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713803881; x=1714408681; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qax0/HGbPdCX4M7gDaYwDwDlZ1cE1xlWdr0Di9/Hmb0=; b=aSIPWqQFqpnJL8L4Ak2gQDuqfsyHrPgUH4L9gVF7yGwczZhDD5hdbLegXMN+Wpr5J1 5EuG+NZsivpji7YKRftJyIuhlquRt18v0bke/oCvWT+oE14vEDfnmd4dUAdsu8hFd+Bq xtVs/d9ksPj0lPM3RdBGeg/pw7yWw5//48Nz8fDsUL1qgfaKTXYsuGCkqFWUPFx1gyXy wQDZMNBS+hOnI3K8gJssuhK6fzHQp91NPMc1xBtJyz7OjBpPEe/WurQrJyduiV2vw84n sv6yxn4bf5zHEtU/24GNCBabs2KkZDBSLif29m4Wv+CROo8AsMppuaxsfHBxKBerz41R n4+Q== X-Forwarded-Encrypted: i=1; AJvYcCXFXfNAiuI4zgRP5AfhabFdhAVT6JpmBKx8mYXnsdID85/WgHZuANB1nv/s4Eh8De+24MGP2NB8CkdmlSw4nGpvOlawipxoYoDWak+J X-Gm-Message-State: AOJu0YxW/0lpmE4XSQJpoavGHFF+I1AR/bTCCHBuECBsNr0M6fm++yeK BXw1XlNqJTKte0EZ/hJ67dvcsq6FQK7yj1+5He9Vy7G+XqBOsVnZaDLObLgdGA4= X-Google-Smtp-Source: AGHT+IEzy7IMdvyIvZX9JXpBHD3JCWT5CYEangjxakk2Yk/cQGKphKCelIukMXUJsOjUWyYnWCSXyA== X-Received: by 2002:adf:f312:0:b0:34a:9bd2:e062 with SMTP id i18-20020adff312000000b0034a9bd2e062mr5682563wro.22.1713803881330; Mon, 22 Apr 2024 09:38:01 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 09:38:00 -0700 (PDT) From: Daniel Thompson Date: Mon, 22 Apr 2024 17:36:00 +0100 Subject: [PATCH v2 7/7] kdb: Simplify management of tmpbuffer in kdb_read() 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: quoted-printable Message-Id: <20240422-kgdb_read_refactor-v2-7-ed51f7d145fe@linaro.org> References: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> In-Reply-To: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> To: Jason Wessel , Douglas Anderson Cc: kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, Daniel Thompson X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3364; i=daniel.thompson@linaro.org; h=from:subject:message-id; bh=d2qYpbUEJ3bo57WTysC1k9+78U0fLX5bGNTDzJBq7DU=; b=owEBbQKS/ZANAwAKAXzjJV0594ihAcsmYgBmJpJPqisf3kvs1fsDrTPdS/Hd2TSSUyPhD/I/e YRmAXjvr7OJAjMEAAEKAB0WIQQvNUFTUPeVarpwrPB84yVdOfeIoQUCZiaSTwAKCRB84yVdOfeI oVLKD/4h96QoGB+ELO66U9tQqvmQKx7Tivdsqq8aKGjehaXAk2JgbjFI62eJd/dwlFkk6fR3PPp uUVId8dKR58fXSpB+yc3dei1qYxbdQf9EnPSvVZr3rzYB7RJeUHdxm629ZwuYZ6eG2IRh9gFwvN uxnsHpmiUhHbjCWpmzcNiBGrKcJEES/T7zITubiAMIR7DhBFztzdWt+Rw4DlF7aKobXBLYXrSng uIuA/fIP6CJQVWpqDAyKENpm6eIMDLRMWKqJtHFGBa9hARFsGv7xpWntSMvtNZxDJ1rtcnymxWU E1MPUBf16UzHJ9728ylZOlKSJgfzpeSVYgZw5WE+pHxEcKo/2+WpSppm7YJCvfObvk886tKI3r7 1avBky2T2w9MTajvja8P57GdQpx/cQeFGuRV/Qm9YQsLqI6PTXtDySCamBKPy/yucQRVoNtyMnN 9nHGtEhlWQ+6eUhZT8rUBBTzLIyXIkkAPDABVaQcNBqxNn2C6JVmra7MWPXWnZu8FzZw6La2tOr ClFQh9AzXn0IShJ7ypZqYoBX87lasKlU8Xa2FvmyuU478qj+Lq/CV9EOZXmF393FOFEVtfaCJ3p wwINiDgepdX9FlUsJPk3IEhCeCEop3FVm2EUFXbFCp9SS7sjZ+rr76/SKZONT0m2hjk9rwtbOv4 95h571eDSbaFKuw== X-Developer-Key: i=daniel.thompson@linaro.org; a=openpgp; fpr=E38BE19861669213F6E2661AA8A4E3BC5B7B28BE The current approach to filling tmpbuffer with completion candidates is confusing, with the buffer management being especially hard to reason about. That's because it doesn't copy the completion canidate into tmpbuffer, instead of copies a whole bunch of other nonsense and then runs the completion stearch from the middle of tmpbuffer! Change this to copy nothing but the completion candidate into tmpbuffer. Pretty much everything else in this patch is renaming to reflect the above change: s/p_tmp/tmpbuffer/ s/buf_size/sizeof(tmpbuffer)/ Signed-off-by: Daniel Thompson Reviewed-by: Douglas Anderson Tested-by: Justin Stitt --- kernel/debug/kdb/kdb_io.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 94a638a9d52fa..640208675c9a8 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -227,8 +227,7 @@ static char *kdb_read(char *buffer, size_t bufsize) int count; int i; int diag, dtab_count; - int key, buf_size, ret; - + int key, ret; =20 diag =3D kdbgetintenv("DTABCOUNT", &dtab_count); if (diag) @@ -310,21 +309,16 @@ static char *kdb_read(char *buffer, size_t bufsize) case 9: /* Tab */ if (tab < 2) ++tab; - p_tmp =3D buffer; - while (*p_tmp =3D=3D ' ') - p_tmp++; - if (p_tmp > cp) - break; - memcpy(tmpbuffer, p_tmp, cp-p_tmp); - *(tmpbuffer + (cp-p_tmp)) =3D '\0'; - p_tmp =3D strrchr(tmpbuffer, ' '); - if (p_tmp) - ++p_tmp; - else - p_tmp =3D tmpbuffer; - len =3D strlen(p_tmp); - buf_size =3D sizeof(tmpbuffer) - (p_tmp - tmpbuffer); - count =3D kallsyms_symbol_complete(p_tmp, buf_size); + + tmp =3D *cp; + *cp =3D '\0'; + p_tmp =3D strrchr(buffer, ' '); + p_tmp =3D (p_tmp ? p_tmp + 1 : buffer); + strscpy(tmpbuffer, p_tmp, sizeof(tmpbuffer)); + *cp =3D tmp; + + len =3D strlen(tmpbuffer); + count =3D kallsyms_symbol_complete(tmpbuffer, sizeof(tmpbuffer)); if (tab =3D=3D 2 && count > 0) { kdb_printf("\n%d symbols are found.", count); if (count > dtab_count) { @@ -336,14 +330,14 @@ static char *kdb_read(char *buffer, size_t bufsize) } kdb_printf("\n"); for (i =3D 0; i < count; i++) { - ret =3D kallsyms_symbol_next(p_tmp, i, buf_size); + ret =3D kallsyms_symbol_next(tmpbuffer, i, sizeof(tmpbuffer)); if (WARN_ON(!ret)) break; if (ret !=3D -E2BIG) - kdb_printf("%s ", p_tmp); + kdb_printf("%s ", tmpbuffer); else - kdb_printf("%s... ", p_tmp); - *(p_tmp + len) =3D '\0'; + kdb_printf("%s... ", tmpbuffer); + tmpbuffer[len] =3D '\0'; } if (i >=3D dtab_count) kdb_printf("..."); @@ -354,14 +348,14 @@ static char *kdb_read(char *buffer, size_t bufsize) kdb_position_cursor(kdb_prompt_str, buffer, cp); } else if (tab !=3D 2 && count > 0) { /* How many new characters do we want from tmpbuffer? */ - len_tmp =3D strlen(p_tmp) - len; + len_tmp =3D strlen(tmpbuffer) - len; if (lastchar + len_tmp >=3D bufend) len_tmp =3D bufend - lastchar; =20 if (len_tmp) { /* + 1 ensures the '\0' is memmove'd */ memmove(cp+len_tmp, cp, (lastchar-cp) + 1); - memcpy(cp, p_tmp+len, len_tmp); + memcpy(cp, tmpbuffer+len, len_tmp); kdb_printf("%s", cp); cp +=3D len_tmp; lastchar +=3D len_tmp; --=20 2.43.0