From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (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 79E7786352 for ; Thu, 13 Nov 2025 13:18:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763039929; cv=none; b=N6gkdqB391j0vl6Zaes717sQbrot/StdX21+0v7kKFo3M9J79tTYuiHEKlPA6xnGp88rnyQvTHbsYf+ES32vpd8iWtRIJtkxJlAu7xCBMWk6kk1+L2RQHO3GLpx7vjXlkevuO28Ns6hx30OG3Y++kNCo8KoIMkc/M/viDehoHhY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763039929; c=relaxed/simple; bh=BBpsJqxEP7v2OZJUgVFcvfvGE7g14MC4OgCuCg6mXEI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=VKmOqSc7bNB7k65NG7cPiTDsW2wJGldMqZpiex/JBDtWfBfoNH5fJWc9c5Vv/5f1dmksaBs2CtbG8qJa7cyl7ppijf2RoSBn6BruK52vAtzsEnEKUk3qumQIJ52RqTqiNdngKMsxVyq/7jBsDLdNwTJ0yDjP93a/r4evqknl42Q= 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=dcQzanlO; arc=none smtp.client-ip=91.218.175.181 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="dcQzanlO" 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=1763039925; 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=4tLLBDb3sXKAaGvQ1VyRAnDZc4+anqcIji71QoAU2NI=; b=dcQzanlO/lJIJYmPY+xye8IcI/QJizffTHZpygExQyRaOVROhPs+qXfck5LxaOGqCcHkc6 +EJ12GmNF9e+ILnPWcK+VgdFY/c1lBUMu+Hhqdnry00mcx5lCNAwAh1kjt2G+quPkWK/b4 3/0D2uGO3Ib7Qdm2XIOAg9/gQ+2q7aQ= From: Thorsten Blum To: Jens Axboe Cc: linux-hardening@vger.kernel.org, Thorsten Blum , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] block: Replace deprecated strcpy in devt_from_devname Date: Thu, 13 Nov 2025 14:18:33 +0100 Message-ID: <20251113131834.45852-1-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Use strnlen() and sizeof(s) instead of hard-coding 31 bytes. strcpy() is deprecated and uses an additional strlen() internally; use memcpy() directly since we already know the length of 'name' and that it is guaranteed to be NUL-terminated. Link: https://github.com/KSPP/linux/issues/88 Signed-off-by: Thorsten Blum --- block/early-lookup.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/early-lookup.c b/block/early-lookup.c index 3fb57f7d2b12..5c30a0cc85a0 100644 --- a/block/early-lookup.c +++ b/block/early-lookup.c @@ -155,10 +155,11 @@ static int __init devt_from_devname(const char *name, dev_t *devt) int part; char s[32]; char *p; + size_t name_len = strnlen(name, sizeof(s)); - if (strlen(name) > 31) + if (name_len == sizeof(s)) return -EINVAL; - strcpy(s, name); + memcpy(s, name, name_len + 1); for (p = s; *p; p++) { if (*p == '/') *p = '!'; -- 2.51.1