Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2615883lqt; Mon, 22 Apr 2024 16:52:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUo5VYHRkFqQPgRWAAXoMle8n7mDWBhy3JtJVCqwGxk/4pXRCi+MFjpsP4hi12KGTseFmdu2md3WJtGb3uFISoE9rRrGhRnxrY8ZPYdSg== X-Google-Smtp-Source: AGHT+IHMWGJ78/g4Uix+MItBj6nBZMBqLVAmo08TgZyr0y+g/5Xt2zyZEB51HssTIdj+wQn8ehBq X-Received: by 2002:a05:620a:461f:b0:790:692b:5644 with SMTP id br31-20020a05620a461f00b00790692b5644mr9349616qkb.52.1713829937601; Mon, 22 Apr 2024 16:52:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713829937; cv=pass; d=google.com; s=arc-20160816; b=rGfT3SeP9wEkCsi5J1ELVNQG5OCSVBgtYa9GckLnJDZbVJLpUYVb1yxZ6LTZpkIJlj awMtup2t6MxJciBNgsCAav9E0iJnMXYLzBvpy9xIRVdr83HnpBCOU/ARTVxGIA6NL6K0 eUapuzYwtAG/XP4mjB13dtTgQkEa4sBROmNSCIszMeq/AlvvJNquCcc+5LFAVQYNJiYq k9QZGE4Lvs8GWCTX0QpR0nOb9EvZd7bCNWoNJNflZX8FNf77JfDnHQcgbidtUBVcH7Ok O5PLkntj2MLOq88GtpSf8hFOIoVrujekUcGUepbpDsnZqmEzar7xkZov1QOpAXIYrYzN 3nxw== 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=mFMZDFCKqtRsg+Es89BVufKPl3Pj2valoSZO9ZIhMr8=; fh=XjK5ncDwCh6sWdTZ3q+KXIz3LIt6+5T0NO3E/zKlo9Q=; b=BCG+TlRlqh6t1Xa4HJvDNAivGuUlPiARw7iKSoDro70GqMKQWE2oGYr+zsunWNkjYJ a1qeothY7lBcjD9g2N4qxUDoe1Woj84BevB7iaXjfwZjgvdL9g1tHnpIzPO1P1xFrAzN piP1lqtujCYfSCHJ5IJg4JD4PBiK1Hx3+ZQcAjI+BMX7OXhuWLOCGg+lmc2zCF5IFzzL 1PTOGgHcG7v48/+YrI7BFwBz1V80DemG+cq2tQB24u9kGL/hY5DnF2OxxIc5flkWwlQW rdbvOq/aqD4/iMafMTUNAmcqxXtjk+ng4Fa3G/oQ9IN/M8lnN6GLcjjfGmoqJS+wzz/A ydRQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VeZc0T32; 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-154210-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154210-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. [147.75.199.223]) by mx.google.com with ESMTPS id ou40-20020a05620a622800b0078eddf7d96csi11342839qkn.249.2024.04.22.16.52.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 16:52:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154210-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VeZc0T32; 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-154210-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154210-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 422861C21116 for ; Mon, 22 Apr 2024 23:52:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 60F5A46436; Mon, 22 Apr 2024 23:52:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="VeZc0T32" Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (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 109144597A for ; Mon, 22 Apr 2024 23:52:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713829930; cv=none; b=tHnHRKSQdrvSncg8recuxY0f3JBO41UF8v0X/2YHha64ndBuQv9cq3PY1BxKg4txvsnqJ1LniIcNarKF14cQPiHIePFU6PuFkTeQLd4CKLY2smr20/gYnXdpjXPIV/HR0CGoNf573IcCRJqglK6yvQVlzUoWYiOdDwUnAG7RBtM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713829930; c=relaxed/simple; bh=4r98zwDgiy1YfXNKtIkT0ExLUuEswdA2nBvFO8XbVmQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=PMsm6aIvpksg6Gwi/Xz/vnU82vem+2+BOuy1dWNzwM1YFES/EeFpgZ+IwS1wEKRerPaW4MLHRqPUb+4dY0zbAwh/eXf1Xn609vxB50EOJaKtCSJoiDhZBxm7SkXpx+SGL48C5lg+Glw/9cXCLkBrPZhQmtMsJcOGxmq5aR5tzrI= 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=VeZc0T32; arc=none smtp.client-ip=209.85.222.182 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-f182.google.com with SMTP id af79cd13be357-78f05afc8d6so347497485a.3 for ; Mon, 22 Apr 2024 16:52:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713829926; x=1714434726; 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=mFMZDFCKqtRsg+Es89BVufKPl3Pj2valoSZO9ZIhMr8=; b=VeZc0T32WzEUv4/+biDjr0w/2Cbn0OdVnZo3bZVW9GoJDPfIUJgI2cMogIQZdmIIip ZOFTPdMhPLLvN+vYVcUB3FtNba/KZI6ulVTcJQVH+mECP7PVx5kH00blshuymQbA+8SJ uN9cn6wA1GZxP2s9sgwUKATDkMNOSsYTkoEug= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713829926; x=1714434726; 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=mFMZDFCKqtRsg+Es89BVufKPl3Pj2valoSZO9ZIhMr8=; b=ABbdIvjloC8Mli4olXwyX8R0wU0x5zl9stCwnQuFyosQOs+VQ9nPiaiCicu/BJFlOx t5nCi8eJBNjJebRcoqO0bxdWCcBHb6zrHtHmMOjPuXD7HQIlQ/CZYJPhKZfhLvaDVrg/ +f1Hgsy+qft4NrdtTx0/wSl1RtbyPceab5eadXC5zIYDElAIeMSHJj4eQEe40weYBk4D ILEdyov8yKhsThLUnjvatieryKG80y1Ts7bN3cuHNB2QY5nssuHgz+oprnb1rRBuMN/S cymd2TPHuyzVIN+5BJRrHwziYxXrN8jxnAJI+uGqxdVtka1hC2hOyeXcHj+crovojqJS 5hxg== X-Forwarded-Encrypted: i=1; AJvYcCU4kGtL4J8iHSz8ADP5iHnjRSAnHd54A+1aIjIeRZf7jY70xuOXvF7LCYLAOn8QU9J147nlFBI+jGlZ1Eq0zjMa/W1BIo9s35wVQyJ6 X-Gm-Message-State: AOJu0Yy+sweFTVZ8sBez6ucb5u+XK/T1rFVHuq1gcdJE6ubI6RiSLWJ2 YhBKjE7gqrfs35tn3INhbVpOpHVi01Z6kvAq569Yl8+bTOIrCbmrc8snGoxfBPZWXOhJw6dqoqg 2ZGCv X-Received: by 2002:a05:620a:166f:b0:78f:1583:fde8 with SMTP id d15-20020a05620a166f00b0078f1583fde8mr11333630qko.62.1713829925949; Mon, 22 Apr 2024 16:52:05 -0700 (PDT) Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com. [209.85.160.169]) by smtp.gmail.com with ESMTPSA id s28-20020a05620a031c00b0078d61d4c810sm4767478qkm.0.2024.04.22.16.52.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Apr 2024 16:52:05 -0700 (PDT) Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-434ffc2b520so79101cf.0 for ; Mon, 22 Apr 2024 16:52:04 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCW6xqWWPIwD+AWoDQAF2KQxLpXiX5fMqVPqRKRsz9co/lKCsDOXRxVaMwHAzrqc7JiT5nroAU5IFJxA/Kj9ECZsssVdZENSp155DCT+ X-Received: by 2002:a05:622a:50a7:b0:439:a613:c4fa with SMTP id fp39-20020a05622a50a700b00439a613c4famr129884qtb.18.1713829924524; Mon, 22 Apr 2024 16:52: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-1-ed51f7d145fe@linaro.org> In-Reply-To: <20240422-kgdb_read_refactor-v2-1-ed51f7d145fe@linaro.org> From: Doug Anderson Date: Mon, 22 Apr 2024 16:51:49 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/7] kdb: Fix buffer overflow during tab-complete To: Daniel Thompson Cc: Jason Wessel , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, Justin Stitt , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, On Mon, Apr 22, 2024 at 9:37=E2=80=AFAM Daniel Thompson wrote: > > 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 obviousl= y > 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+Lqv= C8deA8GziUJLpw@mail.gmail.com/ > Cc: stable@vger.kernel.org > Signed-off-by: Daniel Thompson > --- > kernel/debug/kdb/kdb_io.c | 21 +++++++++++++-------- > 1 file changed, 13 insertions(+), 8 deletions(-) Boy, this function (and especially the tab handling) is hard to read. I spent a bit of time trying to grok it and, as far as I can tell, your patch makes things better and I don't see any bugs. Reviewed-by: Douglas Anderson