Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1643006pxb; Mon, 22 Feb 2021 07:19:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJy69S35io1oagseT/RgG4hb7sGNtYkj234SVr7aPWH5t4LKS04UGRF0/voTDnLoRDtJkwgq X-Received: by 2002:aa7:dd4b:: with SMTP id o11mr23144067edw.303.1614007188516; Mon, 22 Feb 2021 07:19:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614007188; cv=none; d=google.com; s=arc-20160816; b=CUmae6OhI+sYpp8i/ogLJszLyrsqVKEbj8pVQpJd/mOv6bcbpn/CCS8QCMmDuR1ghe IBIlJbhQgdrj/PbN4XDpx9SGCt68tLl9YB7VB06veb/ZS5SQ0z+Mj3RqcyGxoMKuuVHd qX0yTSLw67EX4rdVR1LyF/NtKhyWm3bKy1dH9gFHyKGZ5eD5Rx9HXZrspkrXlVw3BmqG 27buq7JsOt/5ygpzTnnsncrqJBVp9XPSOUB3IJFJUkziKHQM619v7DA8SN7d5HfpkLcB qLcE9f+OZnFWXBF78H3e3zUA0Cddp6rubHSfgFowtdqfgEJq8AnrcL4JPvFgtmcu0nB5 XxRQ== 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=S1lCywCtYVxEsnuw6UX2uJMQ5VyTPpsEmxTnLQJHs4w=; b=Tp9XjiTo056jmSxZkYufcp6BZ1DpgayVs23COHc7WzolZ+LHgy7qyph2TBNxtdDoTZ er2d/wN/6ID43VpeJ6D7UtPPf0Sjb3VmS4vbXaJg8K/W/RWWJlJkYiOSESvGNn52irn2 Pr1AOqFR73ESjVYz9XmB4+84/xfZYQNU0UKU2hEUukiRQRvS6oPg/ZchuvrTbrxTX9Ep XOXq+LdupkAx3boWGFwCJcOxmE2IILJS5bBttlTby5y3UMnqDuKHenI5TBXTCDdtr5sp 33yT7fop3oDaKQSpQvJXBe5HhIwPDmNdq+blPHY8EHv4xoWoH0esEZjbt+z8qpBw1AU+ NvJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rWf86sGX; 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 du4si11996345ejc.53.2021.02.22.07.19.24; Mon, 22 Feb 2021 07:19:48 -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=rWf86sGX; 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 S231424AbhBVPQl (ORCPT + 99 others); Mon, 22 Feb 2021 10:16:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231240AbhBVPNz (ORCPT ); Mon, 22 Feb 2021 10:13:55 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD2C8C061797 for ; Mon, 22 Feb 2021 07:12:49 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id x16so13834961wmk.3 for ; Mon, 22 Feb 2021 07:12:49 -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=S1lCywCtYVxEsnuw6UX2uJMQ5VyTPpsEmxTnLQJHs4w=; b=rWf86sGXPcNotlzO6S3Y7LO5Nm2WfrkvTP72KQo9Y1VVv5HcanSJASCmDSQC/FvS4l 4X+BnIYovgNuWrjBcRMMgByxaJJKo+WuEdB5B4TeeH5KAB/k0o74OaToO8dP5U+NeEuv kjZevojzhOKXgUYIqK4jZ7+a8FFI4fyWPiYx976xmPlhyZGLbZFjCJRnjHuPAx0agih+ CBwler96z49x42STZP1ftWGwflDrYvL5xmIdJrvmSrGhRlJ+bHCMVys2WE6akJcWlLDD pN58SYbZPSp/1g7GyQVoqT/QQavBz69bDTBxGFZjGXmlE5vLK087Q62L8G+gsKUJ9TPk vUPQ== 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=S1lCywCtYVxEsnuw6UX2uJMQ5VyTPpsEmxTnLQJHs4w=; b=AYv1oU44E+0qzSClGvqXgW8drLk8a+bArYxkBrqbf/o3lLzqVFEK7D5jQmXhg8/FZM vr0vleq1Ig7sghyECCg1z9rmzeqEncQWrXuYlgNZ07wgS8+KPDhtJjeGoDjFw3FyRboI FED+2DErA46OpSRPIu2JoBrkYo9kVaVbSMjdLmgn23ZnWTtm/eBe2W/9P4LeQxucAHCy fqmcFhFcrEWrgRUxRsuHCaASHDy9f4aq2WTBiUK4RYMweugj5qhZ+/yWgejEYFOM6/C4 7hSEKGLDzqoHxjyPszZEy2Tp/z6oSB2Qc9RZb0Da6w2Fdq9ENwB41+fAWjnNOcTDxQ0u E6vA== X-Gm-Message-State: AOAM531fYieLqI28fm/8+d9KuFW1I2XPs0fpj19sit+ryPIdiMvCPbxz F8ZmIryUDQ42feh690uHAS9CyDvRpAnoJM+Bg78= X-Received: by 2002:a7b:c14d:: with SMTP id z13mr14117614wmi.6.1614006768018; Mon, 22 Feb 2021 07:12:48 -0800 (PST) Received: from debby (176-141-241-253.abo.bbox.fr. [176.141.241.253]) by smtp.gmail.com with ESMTPSA id m17sm24783581wmq.5.2021.02.22.07.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Feb 2021 07:12:47 -0800 (PST) From: Romain Perier To: Kees Cook , kernel-hardening@lists.openwall.com, Greg Kroah-Hartman Cc: Romain Perier , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org Subject: [PATCH 05/20] kobject: Manual replacement of the deprecated strlcpy() with return values Date: Mon, 22 Feb 2021 16:12:16 +0100 Message-Id: <20210222151231.22572-6-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 --- lib/kobject_uevent.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c index 7998affa45d4..9dca89b76a22 100644 --- a/lib/kobject_uevent.c +++ b/lib/kobject_uevent.c @@ -251,11 +251,11 @@ static int kobj_usermode_filter(struct kobject *kobj) static int init_uevent_argv(struct kobj_uevent_env *env, const char *subsystem) { - int len; + ssize_t len; - len = strlcpy(&env->buf[env->buflen], subsystem, + len = strscpy(&env->buf[env->buflen], subsystem, sizeof(env->buf) - env->buflen); - if (len >= (sizeof(env->buf) - env->buflen)) { + if (len == -E2BIG) { WARN(1, KERN_ERR "init_uevent_argv: buffer size too small\n"); return -ENOMEM; }