From nobody Sat Feb 7 15:06:06 2026 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 60AE6340277 for ; Tue, 27 Jan 2026 11:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769511964; cv=none; b=Hik8x2xTvLHsxozVGEb6s2CIzNI1eYME1RMFwMyFfrQmevh3Wj6+0oNK4PBMEThI7M9HlMDWUsDbB3Pin84rS7hEHX3soVg6hDpgWDUKO56U54xTjupJIEeelNGTLfkk5L3fpzsFlPDQRhqVNg/LREPnTJX6g1J7lJ+Omp4Cct0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769511964; c=relaxed/simple; bh=SZavOIyMlQWdD9RH79jnqDYUuCEoU3G38pJqSDStlvk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=XjqhCb1zFL5xBThWVid3IfdpxJIGSXe7vXBiNkPp1Fa0/r4E3+RAzsuFfS4A/QpfEtlhfnckSr5GiSyUFoqQ9jBrJAo1ut67h4f+9D16RXzVkfAmClE+f8mPZNN6VXn4UYiNi/17vPpAkN//zhn5VY3ckFCJatRP6QqylzL5TXw= 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=Lo/ZCLuw; arc=none smtp.client-ip=91.218.175.185 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="Lo/ZCLuw" 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=1769511959; 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=hZsdMhq6iLkjPyRNRG8K5diYgGVeAVxdxLQ3WjJ5Ji4=; b=Lo/ZCLuwju2REOne3vzlrUfJg86+OyUPAhONpqOgHrQ85qHDB1ad97Mo174uSyaJhzFSaJ dWbOFzZyhNl3n+sx2pCHBHekqbG1mUid49wIZlVV0hmVu2PpWiBfuIRIefisfqZBzrRy4/ 2CgK5Sn00rr60gTLS0U59nuZTwG3yg4= From: Thorsten Blum To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Andrew Morton , Anshuman Khandual , David Hildenbrand , Dev Jain , Josephine Pfeiffer Cc: Thorsten Blum , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] riscv: ptdump: Replace unbounded sprintf() in dump_prot() Date: Tue, 27 Jan 2026 12:05:40 +0100 Message-ID: <20260127110543.436242-1-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Replace the unbounded sprintf("%s", ...) with the faster and safer strscpy(). Replace all other sprintf() calls with the safer snprintf(). Signed-off-by: Thorsten Blum --- arch/riscv/mm/ptdump.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/riscv/mm/ptdump.c b/arch/riscv/mm/ptdump.c index 34299c2b231f..f4b4a9fcbbd8 100644 --- a/arch/riscv/mm/ptdump.c +++ b/arch/riscv/mm/ptdump.c @@ -7,6 +7,7 @@ #include #include #include +#include #include =20 #include @@ -213,21 +214,21 @@ static void dump_prot(struct pg_state *st) val =3D st->current_prot & pte_bits[i].mask; if (val) { if (pte_bits[i].mask =3D=3D _PAGE_SOFT) - sprintf(s, pte_bits[i].set, val >> 8); + snprintf(s, sizeof(s), pte_bits[i].set, val >> 8); #ifdef CONFIG_64BIT else if (pte_bits[i].mask =3D=3D _PAGE_MTMASK_SVPBMT) { if (val =3D=3D _PAGE_NOCACHE_SVPBMT) - sprintf(s, pte_bits[i].set, "NC"); + snprintf(s, sizeof(s), pte_bits[i].set, "NC"); else if (val =3D=3D _PAGE_IO_SVPBMT) - sprintf(s, pte_bits[i].set, "IO"); + snprintf(s, sizeof(s), pte_bits[i].set, "IO"); else - sprintf(s, pte_bits[i].set, "??"); + snprintf(s, sizeof(s), pte_bits[i].set, "??"); } #endif else - sprintf(s, "%s", pte_bits[i].set); + strscpy(s, pte_bits[i].set); } else { - sprintf(s, "%s", pte_bits[i].clear); + strscpy(s, pte_bits[i].clear); } =20 pt_dump_seq_printf(st->seq, " %s", s); --=20 Thorsten Blum GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4