Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1641615pxb; Mon, 22 Feb 2021 07:17:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbRMq+w9a8uPK9+MaH+8JzR8vsI3jMSmLNYs5mDrmovXEFDe4hA/I4LUUpT4zCAwmjAFeH X-Received: by 2002:a05:6402:26d3:: with SMTP id x19mr23034453edd.0.1614007058083; Mon, 22 Feb 2021 07:17:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614007058; cv=none; d=google.com; s=arc-20160816; b=vjq0kmu7XwLbQFmXCz2PvVddgJxZOUR41sPpbaAYS+Ldsamc0Ks5rtwUTeL8QZKOPI m0na1yj/lcsbn75oWSSQymBNTnSjYi/x3/NQ7lMaWnPa+zrJbt34PfKFkNpie4KdULgX ioCCFdyyXuQpk0uiiyT63rH55vRUqPn2zJ1gRPcU0yUbO9XLRYJr300g3eMD3P099uPb HVHbM4ERA3jehjsIicRF8qapH3Hw7vpdxW1sALy3K4hNuqhe5u6Uy1h0VO6fPDyCdQsZ NJxio9DS6IcgeY1VdsGKmi4FVy+ienPjC36uOmZ6BdOYr1WvW9mtXgqweOr1ALbFcikO PlIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pdGuMOt4W9f6d632mZ/3+qcmk+vyhqvdNPaPLq7IjEM=; b=QhTdyc4H+P4PJBTm/UXTEjmYa5eEf55LLHpIBedcNMYPxOYGrwQKw00T9RZDu5kna/ UsxPLeI75BqEeYGJfEDADJMHtZloHczQrzAKuNPwbAceQ0SplOBGonBlkKsgdLPFBeBY aoSCOh8F8BSS9ay9hZqKMgQZ1M+lk7KDXo5q7GUIllEHsNSvSZWl3O/Ij9/O/gXVcbFH Yp5taCvgSnIhZ0Sfhh/bvQeWZCY/DcM/rUPh7wRWh6deZITK2CBHKsPL2ffqQezi5qiB v1J7j1FHA64TTkpGbVfD1JiGBJ9HValJmd/N1U5U7I6U2b8O7Vqup1mj0UQJzkgCrpvL KYSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=k6YPsBKx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y13si12873568edd.436.2021.02.22.07.17.15; Mon, 22 Feb 2021 07:17:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=k6YPsBKx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231345AbhBVPO5 (ORCPT + 99 others); Mon, 22 Feb 2021 10:14:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231226AbhBVPNu (ORCPT ); Mon, 22 Feb 2021 10:13:50 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D1FCC061793; Mon, 22 Feb 2021 07:12:47 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id v1so19442055wrd.6; Mon, 22 Feb 2021 07:12:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pdGuMOt4W9f6d632mZ/3+qcmk+vyhqvdNPaPLq7IjEM=; b=k6YPsBKxhiIVQgrR1NdSYHdWn4S97ym5N5LCHyB5TOSQxclZfqhb+K112mwVOvPdbc YsUsd4glncxcxs/mU+68rO2yBsai6OJMWHsI7TDIBaGyHKBwGGMOcRdSxtby0dHsakBU xudObvNr9cstN2fAOzMrQywEDT+qKOMFCrVBy1Yvo5/K3pN1wuEhu5nMw7+Vn4P+oyzq kPMccoOCphrMrfGWAsxbhPcYfTeCYThv/ZThSHcajVGLTJ648gdvc90RDNiEvAwmz1CF EodIi/cqA2HJ68SYPUU3JACVRe/vGDjIvh4jIeA6QGbl9MIa6ktk+C1cJU8HA7lmYQtu aDrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pdGuMOt4W9f6d632mZ/3+qcmk+vyhqvdNPaPLq7IjEM=; b=fgqmJuN4KsslMmdXYjIp12sX91+G/WcEZOYfWSP/w8IjHsPOG5/ukFFlAs6XFVu7ov iRaJNknjoqN9Odp4MmR3eTJNBSOWwM6IVUnpOjgRZWzL5MflhmAT50pQ9GoCWsev+BgQ 8RcdjfPN6rOGT0hSmXtCdIlsk4fZmk0hyj8fVa8VSwiCGc7pNQSSnTXx10WkQi0rdUdh lRK6V8YchkCSzINycTvTgRiSSwFmpBiA9gNTdTF0fCk55LWa9tG5aafdKyHX+ofRArJj jxvK+b+DDbJTrqsyo2FCcW5rZsKaCiValUMIiG9wcNOjSgJrRLsgF6WZqndAThmbTa+u G9lg== X-Gm-Message-State: AOAM5331oP5EgE+g0QyYZ9rsU2JkiylNPXK+MPzvhq/J83qCBeZCpkZV hBz4Gy4SB0bN/0/sLlivlD1rkBr3yATt1i6RVik= X-Received: by 2002:adf:ff88:: with SMTP id j8mr15600241wrr.62.1614006765655; Mon, 22 Feb 2021 07:12:45 -0800 (PST) Received: from debby (176-141-241-253.abo.bbox.fr. [176.141.241.253]) by smtp.gmail.com with ESMTPSA id m17sm24783472wmq.5.2021.02.22.07.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Feb 2021 07:12:45 -0800 (PST) From: Romain Perier To: Kees Cook , kernel-hardening@lists.openwall.com, Jiri Pirko Cc: Romain Perier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/20] devlink: Manual replacement of the deprecated strlcpy() with return values Date: Mon, 22 Feb 2021 16:12:14 +0100 Message-Id: <20210222151231.22572-4-romain.perier@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210222151231.22572-1-romain.perier@gmail.com> References: <20210222151231.22572-1-romain.perier@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The strlcpy() reads the entire source buffer first, it is dangerous if the source buffer lenght is unbounded or possibility non NULL-terminated. It can lead to linear read overflows, crashes, etc... As recommended in the deprecated interfaces [1], it should be replaced by strscpy. This commit replaces all calls to strlcpy that handle the return values by the corresponding strscpy calls with new handling of the return values (as it is quite different between the two functions). [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy Signed-off-by: Romain Perier --- net/core/devlink.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/core/devlink.c b/net/core/devlink.c index 737b61c2976e..7eb445460c92 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -9461,10 +9461,10 @@ EXPORT_SYMBOL_GPL(devlink_port_param_value_changed); void devlink_param_value_str_fill(union devlink_param_value *dst_val, const char *src) { - size_t len; + ssize_t len; - len = strlcpy(dst_val->vstr, src, __DEVLINK_PARAM_MAX_STRING_VALUE); - WARN_ON(len >= __DEVLINK_PARAM_MAX_STRING_VALUE); + len = strscpy(dst_val->vstr, src, __DEVLINK_PARAM_MAX_STRING_VALUE); + WARN_ON(len == -E2BIG); } EXPORT_SYMBOL_GPL(devlink_param_value_str_fill);