From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796105197; b=bkRc0Qp0zRZO43GiYvVqkoJAdJdodEudq6KpyWpKz1VNswn1qciNfV5MpMIzlIHZa1WN QYE45h3SwuOZUHqQkbqLPGmorZ4T4Lr2cCKpeDfdBFtxJVCaXzXdBNtZv8/Dajs1GZaVv PV+ms3ai1QN6FqqDJqFlpM+evMpPJZiJebNaSS2M+UhZvPldNW36t3inU45ge4vqGl8i9 StSBAN3NDK/fYj6Tw8a9b7ed/5qS4MRtnVEE1P8IUyUvv/mHLKI1Uxwh4+4nzNB3lE+kh axvXjsdYCjMEbFlqZk5I6NDwd4z/VAS8nBfOlxzPFhzGl5afxlPloG2Stbw8nqiiXxw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796105197; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=y0YMo3n5Fy7s/drbW9GbvNEF+91Mj8D1r6jLVBzDYeQ=; b=xkMOL+v/exDaWm+RDmgLkggsXRAlax8jcORThiGPKd//gVQI1PnfdVtW8qtxqg6nIXQ9 zvW7jctH0CgtW+DJT7JZDVjyJbvwRsBzj09uLbkEgbItgSAbOKiTVeYb+FnzX1k7k4M6q gZwiGpb9all8fwzLhYsoYp8TeBxMxtvLBfN8cuHFoYJsqLFLphHVuXeic/G7e8L12LcWB 13zzrsA+KHQIHO0tA6EGB+Rk9maVp0lnXT1W3bsH7m13tb4Xh9y4kZMMO5DxGoKYCAwZR N/VppxM0NVV1EXrmuCE+Lp4OV4Z2P4EYFDDKDAlM7RRZUBFe66HFlr9RauKSA2PwPZQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=UwOyKFya; arc=none smtp.remote-ip=209.85.215.172 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAE7E606A31A for ; Tue, 1 Dec 2026 06:06:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BAE7E606A31A 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.a=rsa-sha256 header.s=20260707 header.b=UwOyKFya Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-cc758830601so8188298a12.2 for ; Mon, 30 Nov 2026 22:06:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796105196; x=1796709996; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=y0YMo3n5Fy7s/drbW9GbvNEF+91Mj8D1r6jLVBzDYeQ=; b=UwOyKFyacpAd3qncBb3CQifKhZDNWuHW3x34nHVEpKEOZ6J0Ah4zmQUwjxSjBipfIf ysqHnONc/Xzqi9FDQJ8/Ln1pqYtFSxymWRxAxj2q5Hb5L9mmKm9/SMURckPtZoRk/NMR Gtoq3YYCqSnTW1qktzSqo7p7KGvwAsYQOw9djXbGhiJn2Rf+TlCFysFcw+PWe9h2RJy/ Vmt9CmEtW0LIhcZBeZkWhqCLVF+jxqb993qWrtIdbDtcWnImt1EC1yMVE4Xlr7BWZoCp D+YeC4CDn2/V8rcz38jkC5jAjyNYd8MsgRJIMBPxOTgKeZJVvwggXD2n3Hzlcvc5/v8l dURg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796105196; x=1796709996; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=y0YMo3n5Fy7s/drbW9GbvNEF+91Mj8D1r6jLVBzDYeQ=; b=Z+a+zycQ4EOFThh9FrNQXrgDuFndfL5EYzpGLOcN++QwT4xzm3NYvHYxR5V+aMZW7G aQYVXGn3etLEaNUXTCaJleGiK/EOUL3RJuJ784iM7TFvSpK/FKc6U7yP3ZTcwn/WyDkp ePqhtyMhacpuPrMxlZJo0yTFlgSrk+zOhTph/pH0W3Vb+qfsQsXi0+5Bp6eA+zf3jZRf cnD7H2n4RcX8kp9Zc/rr+IZT2/9w+ykE7vkIT8scjZTKqPUnPJGrNXvG7/d9eZRPVKaY NgHdBORsJfbO7D5udCk+MZpi4jd2GV6f3bDedwWctHHENpLKCzRevDeV3AAjrTnqgO0x em7A== X-Forwarded-Encrypted: i=1; AL+hErHZqHF6N/T959cmiM77zXKDWa2EWt/AFBFz61bYlAc69SQcj66pi+ET1ankZ2OVn61mq3BN4KX8cuRw@vger.kernel.org X-Gm-Message-State: APuU4Z8GSsh/rsETGJi3CuLye11yrtSo3/ww0P7YqkHbiuvCRNmHrdtF 9i3CYZWzF0226MS5GmlmBucbjFci385jmCerWk2xmz3b934G39ctI4pA X-Gm-Gg: AZFdTZfqLBs+6J9Oqzt86XsIH5jtp0IRbNJ/uXHt4SqJwxokcWjCrYF1a4njMyY4boJ B0PlzS9gQ+8+QgPABaKC+tb79BPA9tJarY+171/8zzDHp6MsQGwDl8NDmslcHD0+PBZTtQ0l3/R QR/t44qV/uXxlRRs+cyPiwt3tr5UsYTAnI98kKrGbR/OHhdUSsrR3OcHLsxn2msC6lg+3WNlUeY VvBi72x1lNnyjqwZC/YwN7OfAJfjyNlZkZ1pnwNUN+99JDAiy62B+apbxB65cTCXQYxfJIPl0PX WPH3gHGlVRh7YXxLS/+0kdll9JxUq9j9FpjmeQ3w9jLuMNZXps7xomjBf9APNcQ5uFEUdstfrTn jNsSUz6XALaGYPpMiwMd1ku3W/fJLN+6BobVFn7ul03X/cIlxi8xa1IHuNki3TG6JUueytQPHxl OUS2aVNPiLf49Z9tEpp7hWgiKzwitHL3oWl3ZXtH8vLTozEL4SekreBEzavGczH4O0bHSJiQTWS 6T3Tobuv/Mvy/0gcD0xPMVVoBllBQAkWBM51BM75hPxta+jzMOv9F/rwyZA3wu4wbHW72FI+jcU bU3IZLSf/hNufGKQlHC9y3uEwJO2lWH4sPO7chFEI0vanMcSR3aveU9Q8h64lqEqSE52MFg2vzT KQAIjpM8= X-Received: by 2002:a17:90b:258e:b0:3b4:fd89:5f99 with SMTP id 98e67ed59e1d1-3b4fd896a22mr20992299a91.17.1796105195766; Mon, 30 Nov 2026 22:06:35 -0800 (PST) Received: from DESKTOP-TPPBPA1 (36-226-254-86.dynamic-ip.hinet.net. [36.226.254.86]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5210be133sm24460178a91.11.2026.11.30.22.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 22:06:35 -0800 (PST) From: Lin Tzu Yang To: "Martin K . Petersen" Cc: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] scsi: target: fix one-byte overflow in dbroot show Date: Tue, 1 Dec 2026 14:06:32 +0800 Message-ID: <20261201060632.880022-1-rongh7426@gmail.com> X-Mailer: git-send-email 2.51.1.windows.1 X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit dbroot_store() accepts up to DB_ROOT_LEN - 1 = 4095 bytes, as long as the string names an existing directory. A path made of 4095 slashes resolves to "/", so it is accepted and stored as is. dbroot_show() then prints it with sprintf(page, "%s\n", db_root), which writes 4095 characters, the newline and the terminating NUL into the PAGE_SIZE configfs buffer: 4097 bytes. KASAN reports it on the first read: BUG: KASAN: slab-out-of-bounds in vsnprintf+0xdd8/0xdfc Write of size 1 at addr ffff000012a37000 by task cat/109 ... sprintf+0xb0/0xec target_core_item_dbroot_show+0x28/0x40 configfs_read_iter+0x284/0x46c Use sysfs_emit(), which is bounded by PAGE_SIZE. It is already used elsewhere in this file. Fixes: a96e9783e058 ("target: make target db location configurable") Cc: stable@vger.kernel.org Signed-off-by: Lin Tzu Yang --- The bug was found with a small configfs fuzzing script and the fix was written with AI assistance (Claude); I reviewed and tested it. The patch is against scsi for-next; it was tested in QEMU (arm64, KASAN) on configfs-next (2e0fad9d2eae), where this function is identical. Before: KASAN report on reading back a 4095-byte dbroot. After: no report, the read returns the 4095 characters. drivers/target/target_core_configfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index 2b19a95600..199e5e79b7 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -101,7 +101,7 @@ static char db_root_stage[DB_ROOT_LEN]; static ssize_t target_core_item_dbroot_show(struct config_item *item, char *page) { - return sprintf(page, "%s\n", db_root); + return sysfs_emit(page, "%s\n", db_root); } static ssize_t target_core_item_dbroot_store(struct config_item *item, -- 2.47.3