From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6116F4A13BB for ; Tue, 9 Jun 2026 15:13:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781018034; cv=none; b=Ebc8IOwWztDJhLPG39lxLitnRwIwA4/nQZ0GBJPEY7GzJzVSlqYs9zQjjR3Q7GDDMFg9qYUhLwc+oPJ3T20yy+eGscni2ay0MXmTixrYj4G/tj36IehRFoAKN9hQ/8KkwoQpbRrwCUKJ/H/Ly6QsEsSV3d0m6CCKlEMEgrPdVW8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781018034; c=relaxed/simple; bh=Tgj2/f5KwE1aGzhSuEmxWHXJ26+0zAS918oxJXslIPw=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fcA3XqMNWIbgmT2MfTcG0/gbfe4Trie2uEmyem2Ba/tR/CWQBk3Z/fciTWSxHO3puheIyIrPNGc8FVw8vUYc6v9Pb1igsddwCHJf66/8sziISEG/urvr6rJLLg66yc65IbxLcAgpIjyJoSGokUcT7vsixpkyiZ3ZU3W6lDLBt1o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eDnmlTR5; arc=none smtp.client-ip=209.85.221.44 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.b="eDnmlTR5" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-45ef6565cfdso2680984f8f.0 for ; Tue, 09 Jun 2026 08:13:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781018021; x=1781622821; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=LS9BfQsDmesJT0AInGwOXq/X3DAmc3WIA3Pzjrg2pfY=; b=eDnmlTR51Qisn8G1HGxRzhpM/4f8MiowQoWhGCv01Ro0aAVP25snMxrWmcSmFcTQa0 kSqbawpNnq8FhnzmVbETXa0AnDSm4stItKLC4Vb+bMhOUcR10lyMCOcZgmKWbdPWBfGc wCLJUWKNTcBfXOrfJtmb0tgKJkPFbwgWf9ORzDuJ3bziClvqziatwyT1BbLOOgzijpzK bbX5zZb7b3RpVHqM1qG1Lqn+ZeCKvjm8kQUWqmQE9N609q5oyuTzJX+445Bm1oEnukUz 0Ojn7+KOKd3Ojcsh8qy6EKtFUukke8gP+aksgI/fnF4vwSMZLx4PEgQMyI7GQEVacC/i OkYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781018021; x=1781622821; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=LS9BfQsDmesJT0AInGwOXq/X3DAmc3WIA3Pzjrg2pfY=; b=iw8noksYuCsbb8tA8igjKnDOXu4kEBeiYRCkisEQsTahJ/BICA+WXG34EF+nqyfofi za1Zx2R1nR6bzxybgA1vPkLXO1qbXxOIMOfZYNrgaVkZ0cpVreamxiXmsn7zessQpIrD mCZ39aSFRhtVus7ESbfqWMU+q3OfEunJtnP9IevBzXeKdOSsGWhiwX5sZakNOKvzwkMT BiRGMCiODDVaGtXPcfX3a1LX4Q5gfKhNnrpE2eRlsojyBOXGgt5j4fCMRMx5YDFmrv5b ASMoCj4Y+UUpO7mBHrqwDHW5L58ALNTdpc3HCZTmDPOrFA1g5KLHO127wO76QjbTZR3z RqxQ== X-Forwarded-Encrypted: i=1; AFNElJ/RPBwBoxwyssEwVxBnwLANd4RrbUYbdkWKdgvWQ0Ax5uyQiYKKnG0fmKqyAmaZbNbBkLKApQA6UUZ4rHc=@vger.kernel.org X-Gm-Message-State: AOJu0YzkyN5JYGupEMt6NByRMwwaII+SderVh3nRmZF+Sr+weOeHOUnh +LN+hqla1yp/1rMsKrLilyhHCaCoPs51Uij5TGIsiGJPT88IDa1Bvbvx X-Gm-Gg: Acq92OFjCdEkNjl0YtKkJnFp/jac5NYd0/bgBTR5MCe94ql7Oia3JsQNufKgea4OcUm 554GXVTaHTfGRFtWIDgtRruD2EnyvzBjBDXIgJZQGEBfW8CtBUgVgJj8sEQzTIG65zogEOjf1aP oQKX+AUNLsnE7SVr4g5daTrEBh/3kfuOLr3MtJNybWfwBGh0VZAnszRrzZ/dzjmCDNJhIOsoP6x uISG+TBXZ8tG5FjekExhWr2taZTuehZywjSj2WDZJXb6J9hfXxV8J0fHNr0Iu0WxJpf2CNMv0rY rE3jwD5MdpCb2hw9NJ5J67ozumjxOSFkL5XuccIIPkaHKOZEl5cP7bMp2RvCnPIVWQ6Rpi6/v8T gLbKVH8sc6WtT+RoVeU+3AHiXp6NrRzWc3SFCHIv22jYDMQcUaCz0IWSDnSgT7TAgpXO1/bQ4FE mb67VrNzpbYRIfuZJWjq20R3PbjvcsrETtH2qwMLJxEjhKuz/eoNr9XBGhw2J7/QjewHk2C9g= X-Received: by 2002:a05:6000:4312:b0:45e:ea9b:edfb with SMTP id ffacd0b85a97d-460566db7d0mr4546819f8f.39.1781018020420; Tue, 09 Jun 2026 08:13:40 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-46028a6dce6sm55897116f8f.30.2026.06.09.08.13.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2026 08:13:40 -0700 (PDT) Date: Tue, 9 Jun 2026 16:13:38 +0100 From: David Laight To: Paolo Abeni Cc: Kees Cook , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Arnd Bergmann , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Jiri Pirko Subject: Re: [PATCH net-next] net/devlink: Use strscpy() to copy strings into arrays Message-ID: <20260609161338.2222ff26@pumpkin> In-Reply-To: References: <20260608095523.2606-13-david.laight.linux@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 9 Jun 2026 15:39:35 +0200 Paolo Abeni wrote: > On 6/8/26 11:54 AM, david.laight.linux@gmail.com wrote: > > From: David Laight > > > > Replacing strcpy() with strscpy() ensures that overflow of the target > > buffer cannot happen. > > > > Signed-off-by: David Laight > > --- > > This is one of a group of patches that remove potentially unbounded > > strcpy() calls. > > > > They are mostly replaced by strscpy() or, when strlen() has just been > > called, with memcpy() (usually including the '\0'). > > > > Calls with copy string literals into arrays are left unchanged. > > They are safe and easily detected as such. > > > > The changes were made by getting the compiler to detect the calls and > > then fixing the code by hand. > > > > Note that all the changes are only compile tested. > > > > Some Makefiles were changed to allow files to contain strcpy(). > > As well as 'difficult to fix' files, this included 'show' functions > > as they really need to use sysfs_emit() or seq_printf(). > > > > All the patches are being sent individually to avoid very long cc lists. > > Apologies for the terse commit messages and likely unexpected tags. > > (There are about 100 patches in total.) > > > > net/devlink/port.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/net/devlink/port.c b/net/devlink/port.c > > index 485029d43428..108926d3f899 100644 > > --- a/net/devlink/port.c > > +++ b/net/devlink/port.c > > @@ -1222,7 +1222,7 @@ static void __devlink_port_type_set(struct devlink_port *devlink_port, > > devlink_port->type_eth.ifindex = netdev->ifindex; > > BUILD_BUG_ON(sizeof(devlink_port->type_eth.ifname) != > > sizeof(netdev->name)); > > - strcpy(devlink_port->type_eth.ifname, netdev->name); > > + strscpy(devlink_port->type_eth.ifname, netdev->name); > > Given the above BUILD_BUG, I don't see how this change can help?!? > > Generally speaking, I suggest restricting this kind of tool-assisted > changes to real problems (if any). My aim is to get to the point where the calling strcpy() is invalid unless it is used to copy a string literal into an array. If/when all the .c files are changed the .h file change can be committed to stop any new potential unbounded copies being added. I do want to look at the 'fortify' version of strspcy(). The current version can call strnlen() and then real_strscpy(), so ends up doing the length scan twice. (Never mind how much gets inlined.) strscpy() between arrays could be implemented as a memcpy() of the shorter length and an explicit zero of the final byte. With the BUILD_BUG_ON() (which I didn't notice) the above could be e memcpy(). -- David > > Thanks, > > Paolo >