Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2616291lqt; Mon, 22 Apr 2024 16:53:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVMxTfcFT5NLT5EtUy5ZD0n+x/+wbimycjWCamDPP3w1q+95R5dam8ir/CjQQ7TXLegVa3n0HL66usb0EBBW2qXhJgzIUeotcib0Db39w== X-Google-Smtp-Source: AGHT+IFGa6TVeavFRzjTjUGhVpRGi/6Cter9roGaGeFLSyxMPfeZUF3cJv0U/+hUmXpAKMu7E+Kx X-Received: by 2002:a4a:8c65:0:b0:5ac:9e85:59d8 with SMTP id v34-20020a4a8c65000000b005ac9e8559d8mr13313469ooj.1.1713830018441; Mon, 22 Apr 2024 16:53:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713830018; cv=pass; d=google.com; s=arc-20160816; b=eR4Xehel9wPO/U3PDfyIi5iQC0k98qzB8/QlAirKuMDUgqMjYJ+s6DQ18DQPwSksHO 1k2HDqytfgCp+Kfm4UGIbHinkqgwtXXS9CSbQHc22Rk8xWdWndOUel3s0gkcJUcpz3/m H69VRaOBIWWPpMs+hqajEvuUBC9+hV7/i/CYa5I7r9NarVYB1Bwo8NYz9JxXcBytqG9h XVHsXOfL838oV/VA/BixZF9h5WHQOy6dZCeBDyI+XJvet2MAZ1R7NRkWVWCAEKuyq4Qm rM4CjXPaGKZug2nq7AqV2YQMwZ4QRKJ8axK5BsX+5IobUYBbcXuaZAWZ3f4HQKooEmi7 Qsdw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=OvKHZ9JjRUWbi49dOaz2jnKn8wC1TnFH6x1+VhyrjCQ=; fh=W7bdG+NCjCaCvVA0YIvnMPW0uoZdoiJNBhyNxGvQ9Co=; b=t4BUzpeGWjmz6fUhArc6fPikdK0Z/tw/0k0QGzOkzIqa7/BAz4B57wU8nU4SLkKJrl qqRJPgOCm1C+C1xYIglim5C3TVG5/Npj1+cN6ApvxLxuzz4T0FPvNumc1H10nPMD00nc kgWbOIMzweVZ8dFVuE7wNKK1Ma0MfjEWmwwQ1PGYF3aH0B9m79B6zml6NyZoLhP06gLy LSccjPOmPHZ0A03drKXIEaUHDVyobQzie5nInVBnS+SBJGi+Nl2S334g7zq8O8XeB0RY U5y/shTCYrfFooo+GxXEQkior/CYGDFIxCIzURBb5S9mg3SZkT0aWy9EZu7A9OXuAr2E SMRg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Vexbhy1t; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-154216-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154216-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id k12-20020ac85fcc000000b00439de644610si1395924qta.671.2024.04.22.16.53.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 16:53:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154216-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Vexbhy1t; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-154216-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154216-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1F7741C21546 for ; Mon, 22 Apr 2024 23:53:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94AA747796; Mon, 22 Apr 2024 23:53:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Vexbhy1t" Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (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 3C3B646433 for ; Mon, 22 Apr 2024 23:53:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713829988; cv=none; b=uG0F/2v2OnNGSHBtkHOYvDczePqYkt7Cxrn+FCcazUUVe+lqagXyxMaO5kiuAau7YBsV/68g+K/wMWNQr+TKev79gNk6vWWc20l3Kd/9/gvYRQX8+e22YAWGOFl3CkT8O/Jbw7NNaPhY2DWUp2fTdJvgCSfibLfwtmAX7FaBOdI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713829988; c=relaxed/simple; bh=iXV0L1N+Lrq9i/jVw377JzbRRAKm374wRqrzKNfzVV0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=UCHPb4XQ6L5S8GLjP/s+gxI10530+Zxje2arQiG+Q515j/AaV0Ua3eE6rPM9zSpQvVTuKw3Th/chNfUhDuMOxCswMPH2bsMUmZS5YfRBpFkqjVYFHrN3IlsKE8d1vkzWiBPaSZGobpVfrR7IXWjO2OMAqwlCyzzT2FCmO5fRt6A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Vexbhy1t; arc=none smtp.client-ip=209.85.222.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-78f03917484so355912985a.3 for ; Mon, 22 Apr 2024 16:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713829985; x=1714434785; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=OvKHZ9JjRUWbi49dOaz2jnKn8wC1TnFH6x1+VhyrjCQ=; b=Vexbhy1thr3evOmNrdpJ7X1qnDGrrRZ+Vic6Va81NvCXZ1CsYcM2IAZUFUCUqngfWJ IneLkj4SOFHVJga2RHHP1/i0C8a6cgWLLAoUie/VNLl/LXWUQhXtR7zxsh4E3TK03D1Q qov9T02g5/46sSKplU1GWa76YE8mKIKZGmlxQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713829985; x=1714434785; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OvKHZ9JjRUWbi49dOaz2jnKn8wC1TnFH6x1+VhyrjCQ=; b=A/k5TJEzxC8HmNWAhtzACNpDmLp332Bcs7QSN4DiW+ZlLfVn+LClokJLr+0YGLAr8l UaYeeba+hqkt4sAKsg3mYK1RdlOqr0k6R2It8iYPcE9DGviiehjGIfeCBmHW3U8lG42K 2Fq95BFFQFDLLSQZn7QVuXlMxvS0H1cgXQ5HCPVdmRLLhn/tR4g7f72FQfoBI4JP5IVh exagChLNjRS1WUjroSLpl7n99rM+/pdtnmL6WjUum/Xt2HLiEnKgb3IAiydrcceMyB9R cAbvRR386W3jnEnKGD8szkNggyP6++QzFZmdB+W8umBg5DHfTpathqYIE15X666tDlCk 197w== X-Forwarded-Encrypted: i=1; AJvYcCWOFzP86jokuaPSQ5lrUlEYG6OxstENatNKTWBc8lpEIa/tIf4cev5iV94d74id6A0IvQRDpXgwTpRXUZ2FhTU6g0CGlSUMvqM06D8y X-Gm-Message-State: AOJu0YxEmSXK95HSs9RVnFX3htqKYImspeAiZBw/8DCE18LP3ntCe1iP usdv/m8CB1LhdQuSHUAboY+P53lgYx3sjcRSOVTlw9UEq4qyxxzCQBz16OATuVFtOMtNZpypdbu ez0TV X-Received: by 2002:a05:620a:8221:b0:78e:f092:88d4 with SMTP id ow33-20020a05620a822100b0078ef09288d4mr12156775qkn.70.1713829985547; Mon, 22 Apr 2024 16:53:05 -0700 (PDT) Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com. [209.85.160.180]) by smtp.gmail.com with ESMTPSA id du30-20020a05620a47de00b0078d65fbde2bsm4758217qkb.86.2024.04.22.16.53.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Apr 2024 16:53:04 -0700 (PDT) Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-436ed871225so71831cf.1 for ; Mon, 22 Apr 2024 16:53:04 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCVI8UCW3oPQo4Z2hSvJFsrOjmuRDbyznXAVKMjZ3Q9aNS5zowIdQ4fz3r87dOqNso0dVjpQuZe0aMy//jxRSZtnR9I+hwjr0WhFWd2+ X-Received: by 2002:ac8:7c6:0:b0:439:b85a:3fa with SMTP id m6-20020ac807c6000000b00439b85a03famr67307qth.11.1713829984304; Mon, 22 Apr 2024 16:53:04 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240422-kgdb_read_refactor-v2-0-ed51f7d145fe@linaro.org> <20240422-kgdb_read_refactor-v2-7-ed51f7d145fe@linaro.org> In-Reply-To: <20240422-kgdb_read_refactor-v2-7-ed51f7d145fe@linaro.org> From: Doug Anderson Date: Mon, 22 Apr 2024 16:52:52 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 7/7] kdb: Simplify management of tmpbuffer in kdb_read() To: Daniel Thompson Cc: Jason Wessel , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, On Mon, Apr 22, 2024 at 9:38=E2=80=AFAM Daniel Thompson wrote: > > 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 > --- > kernel/debug/kdb/kdb_io.c | 40 +++++++++++++++++----------------------- > 1 file changed, 17 insertions(+), 23 deletions(-) Definitely an improvement. Reviewed-by: Douglas Anderson > 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; > > 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)); You're now using strscpy() here. Is that actually important, or are you just following good practices and being extra paranoid? If it's actually important, this probably also needs to be CCed to stable, right? The old code just assumed that it could copy the whole buffer into tmpbuffer. I assume that was OK, but it wasn't documented in the function comments that there was a maximum size that buffer could be... -Doug