From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA06C40DFA4 for ; Thu, 30 Apr 2026 09:04:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777539870; cv=none; b=nvovWXx64/5JFKQrvPtK0+Wl0d6JY/ES5ntKaWJBXpqqKo5RXnbsZmurPP3tWXHYP5uuTklqKGG4h7lFNrz+qetgjMcOLuId6hqDa/ZzGE6Rsdmc7OUN21DIQMYQVKBDtHSnvc0q5Z+RDA9CZkfm2bVcaVA3ZMV2NnroXDWWG0Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777539870; c=relaxed/simple; bh=8wFDzUxr55oMjtyI1hLfzbTNBHQlMyKNLozpZQ8+GdU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=PPvZbRmtflcoXKkayoTv8zDSnQ/cXiRmYR7I5BI2rfQQPYoK0v/2bva4AMz6jZJgkLf5kjdSrfVkHECMrRU5NSFj3eNC+PrJx2cEGSVwHi+S4HtlsqZWGqJym1KJquJuWZNgV1RWaj23on8A7WXlPKJmq3AwjGFAVWwyKmf8/oY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=jgY4v78k; arc=none smtp.client-ip=95.215.58.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jgY4v78k" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1777539866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=+j0BLqzx/slMejfsYuF458WXMh0JxgFVvSg0wEqf06w=; b=jgY4v78kuxsAkxkTqYaRM/K6p9jMT4sE86aAxpo66sWlpfHnKOj5DUvw0C4G8s8FvH4AwQ n7uGzF0B5pCYho4oX49o7x3FveRHrcrBBq7yYJ0EJskeYhRglQ6MLLwrGp0p1TXQ7E9Uj5 hSSGM4hHbMmzSbIQTYt323TSHMsZynw= From: Thorsten Blum To: Chris Zankel , Max Filippov Cc: Thorsten Blum , linux-kernel@vger.kernel.org Subject: [PATCH] tty: xtensa/iss: use strnlen to improve iss_console_write Date: Thu, 30 Apr 2026 11:02:54 +0200 Message-ID: <20260430090253.237654-3-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1037; i=thorsten.blum@linux.dev; h=from:subject; bh=8wFDzUxr55oMjtyI1hLfzbTNBHQlMyKNLozpZQ8+GdU=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDJmfpfa+m5UW3mB7+6aE6CXmJx9sN1jMm5GVfnbTnCu3F 4R+e/cmoqOUhUGMi0FWTJHlwawfM3xLayo3mUTshJnDygQyhIGLUwAmsm0rw3+3PSypjYkVeyPF 7u5danl9Q8xnXqfmRQ+3Pko8ZK4bn7WF4Z9F6zq29Su9vSRaohlE45M/5+W73/5sx6VSNMvgc/H dmwwA X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Use strnlen() to limit scanning 's' to 'count' bytes. Use the length of 's' to decide if simc_write() should be called instead of dereferencing it first and then calling strlen(). With strnlen(), iss_console_write() is further hardened against callers where 's' is not NUL-terminated. Signed-off-by: Thorsten Blum --- arch/xtensa/platforms/iss/console.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c index 8b95221375a8..8e54625cb2ba 100644 --- a/arch/xtensa/platforms/iss/console.c +++ b/arch/xtensa/platforms/iss/console.c @@ -166,8 +166,9 @@ late_initcall(rs_init); static void iss_console_write(struct console *co, const char *s, unsigned count) { - if (s && *s != 0) - simc_write(1, s, min(count, strlen(s))); + count = s ? strnlen(s, count) : 0; + if (count) + simc_write(1, s, count); } static struct tty_driver* iss_console_device(struct console *c, int *index)