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 B8576278161 for ; Sun, 10 May 2026 16:55:03 +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=1778432106; cv=none; b=qLZvinUOawqcV6Oq9yDiDMteGemKbsSt2oDhDqwDSeP9isaxvJ8nc0ljpIAbaMKzM+sDp3gbgCiq1K98zM1kCXX6ZJtwA5B5PXthDMGrlf32fotnHLw0abLuZ2vMFLFCdUGlcMyPZAGDWPd852TafQ5Ojzc6r7/QBwfyZgI1pXE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778432106; c=relaxed/simple; bh=9QU6JQBnJSTvkHt4s2chb6UGQgx22xxDss11LLTomps=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=f9QL+E++la9tXTjvOLAhol5/kpWL/MCf3Re+ThmH6+e57lSRA/EIv0xfis+ZzJNSYbHp+JIYH8bTBCXyzivG5WQNBP7c3rDA653JOKky4iYzNUPs+IirwNXj13KzfSn7K67bH8JjM2qjEaKGAureWaZRs/xmha0FUCb70QuPits= 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=L3MDoQxa; 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="L3MDoQxa" 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=1778432101; 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=2OBzuW9P7eODNU5hYdcV6ou8oladCxtRgVfmGhmczYI=; b=L3MDoQxatDs7iYyHRS6BCcM7AruD9bUlD1xQR7dh1tsZLifM6GtBIEbJpFqGkOTUKdhz6D UpEMXEHs1E+exel/qljgBv0NrQUXo8ssvjMC//Gg6LaMe76KElCctwl3xFnTK4UJAX9j3h NDgSXIZI0te0Ar9OSu4BWIksqPQ8npk= From: Thorsten Blum To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: Thorsten Blum , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] riscv: use sysfs_emit in cpu_show_ghostwrite Date: Sun, 10 May 2026 18:54:21 +0200 Message-ID: <20260510165420.109453-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=1536; i=thorsten.blum@linux.dev; h=from:subject; bh=9QU6JQBnJSTvkHt4s2chb6UGQgx22xxDss11LLTomps=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFkMO2w+LPi3/qlVxvvoR5rGqV+PKPu/N6naf4Z5pkJhs 9Z5VaPujlIWBjEuBlkxRZYHs37M8C2tqdxkErETZg4rE8gQBi5OAZjInDxGhiPCElESXoqyQXsf v7Q1e+u8Rc36vcTVX0mFL6/eVtU5N5vhJ2POlgehEssDJO/0rN0rZDeReYvYOqPIs987p/CcLuj NZgAA X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Replace sprintf() with sysfs_emit() in cpu_show_ghostwrite(), which is preferred for formatting sysfs output because it provides safer bounds checking. While the current code only emits fixed strings that fit easily within PAGE_SIZE, use sysfs_emit() to follow secure coding best practices. Signed-off-by: Thorsten Blum --- arch/riscv/kernel/bugs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/riscv/kernel/bugs.c b/arch/riscv/kernel/bugs.c index 3655fe7d678c..e5758e3f1c7e 100644 --- a/arch/riscv/kernel/bugs.c +++ b/arch/riscv/kernel/bugs.c @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include @@ -46,15 +46,15 @@ ssize_t cpu_show_ghostwrite(struct device *dev, struct device_attribute *attr, c if (IS_ENABLED(CONFIG_RISCV_ISA_XTHEADVECTOR)) { switch (ghostwrite_state) { case UNAFFECTED: - return sprintf(buf, "Not affected\n"); + return sysfs_emit(buf, "Not affected\n"); case MITIGATED: - return sprintf(buf, "Mitigation: xtheadvector disabled\n"); + return sysfs_emit(buf, "Mitigation: xtheadvector disabled\n"); case VULNERABLE: fallthrough; default: - return sprintf(buf, "Vulnerable\n"); + return sysfs_emit(buf, "Vulnerable\n"); } - } else { - return sprintf(buf, "Not affected\n"); } + + return sysfs_emit(buf, "Not affected\n"); }