Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp35730445rwd; Mon, 10 Jul 2023 11:39:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlFYdJ54piMTtzACZ8nNr0Nkvfugo+ybgw3e8HBb6XuzZ1psvNdK6i8fZw3Qrywe2nFEqzBW X-Received: by 2002:a2e:9658:0:b0:2b5:68ad:291f with SMTP id z24-20020a2e9658000000b002b568ad291fmr10413282ljh.19.1689014370756; Mon, 10 Jul 2023 11:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689014370; cv=none; d=google.com; s=arc-20160816; b=Fi338i7BMbv668DQh/ZWK2/zDWBHRMDCA+EizL6sbFWSFpn3x8Ppg+J9+ujxm7FLa2 QhvJ3psqIOu/EFHdz21Gvoe3DkF4DS9GNKl2z4KecGDGXqoZgd1k1uKX38whGTAH/SR3 nTYmB63eEhhrz6pyms+cXGFkPq58HuBXg/+iyHderh2b24u5eabj80pQ7lIDhYlKeOBK hY40UXz5/WsypwwCxCd1Ska1EBPk6YZzyRQaKT51rbwokEg0qPC83E9S6gTa2mc7bTef SSXnsizZHN6ud5ztQ/YYquK4UwwuDSh8ZeYlIDf9voK+v0RlG+EU80lZRAN3aXJgQmXL tzJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=dThlKftpvb1E4fm1zDxlvj7BacTYHr5aY/low3oUN7s=; fh=Chs6ARtlRteu2k4U0AOnJmQVYID2otnmmCB/fIVQTjo=; b=emYqp/XITsltCzJGY1fQuy8+SA3IZk1YAS8G2gu0s6RmdYf9ZWS0ONHw+D98b8Pasl MjzzqQkVfXhyWQFasEhDRN2RvxrpE86sslWOzrgW6y31Hq2UPU6q5pr0o2ZmYEDAvMwh vrN84/YP+FMwIRHElShV/3U1aDQcj9c+drPv7SD+5c7vqzD37K7jLCQLfMAbaD/pjils p653mbJdr9c7sgRPy55xK1nKBiz4ApMceJWEiJeEBDodmwy1Mb2TRUcTYVnkWwp7G9qc Hw7Yl0BKa8gTrffMXW6Z3kfZ8h/sh4JQz2kRBzQ3pp78CYw7wGtZXfZB1p/UWgzWIj4x nKDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=h4r2LsVL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz9-20020a170906cd0900b009930371a03csi118473ejb.1001.2023.07.10.11.39.06; Mon, 10 Jul 2023 11:39:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=h4r2LsVL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230455AbjGJSG7 (ORCPT + 99 others); Mon, 10 Jul 2023 14:06:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbjGJSG6 (ORCPT ); Mon, 10 Jul 2023 14:06:58 -0400 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60DDDAB; Mon, 10 Jul 2023 11:06:57 -0700 (PDT) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-579de633419so54733997b3.3; Mon, 10 Jul 2023 11:06:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689012416; x=1691604416; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dThlKftpvb1E4fm1zDxlvj7BacTYHr5aY/low3oUN7s=; b=h4r2LsVLGXGvJLgAVbXBSZx6sxAfUNEQUFHN6gb3Tm9FYLDCLT0LPJAZx8OvP/UrL6 bYrhk8iIX8SIaYVdFbeDCOXVPOfLC590huH4ZvKULlMi2fUXAb+I1gUdkhRrzryK63yU qpjJBAMm9gNCBb0uKXKj492XG7b5k1l9bnjsfNYY9id9XudCpkVgn4QI7u0Fbm2VcaMh zm3xD3J2+EbJaJ5olgi2vAc1Z15HMNROcPLm2eQ+jJi4FEiMOv/0poxXgFrC3nDBcsGC sLAjYK2qEZK5XzZcY8MKEYmmKJRU8dUsyAciozzxhpWDPHqSfO0KJ5c8liwucy7Us1cS IEAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689012416; x=1691604416; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dThlKftpvb1E4fm1zDxlvj7BacTYHr5aY/low3oUN7s=; b=mAPrHFAEOU4l5oFOMAWTxS7ASyPuANQCattdQoeoQNEy64N+FZH0hhVmBlllzfvKqW 9Wq6gGvIQsG6p+ofUeWOXYxnkAYcU1NH0ZKtxDBtbOFMJHkxc6P667nWVQk1VWZnt65r 4p1lwJ+Er4F1yNZutBNmsi25Aj8bwzqaTC4nDol7ynjCJHp1ck+BtRr1qcGnOLYIpEYg z2jYXjwAUZ0T2EsB9dCIgYWi1qX2M6OfQiQAKWq3jDE3CUrkuaN7b+GoXeMHqG1cRlGv HYW56yZ09YFzZRv8kDFjEQQ2rkIvWmPBFMqCKETXeEt21JCY5goe7p4i2KKy5j3Gm6YZ hynw== X-Gm-Message-State: ABy/qLb3KAB00J9EVwxsOysWYJI355IU/ZwGna/+2sKLsgtrU4tGnyrH TLHj9rkYuTOXsFKCMmhSuWNOGHCX15ZIfb7CuL4= X-Received: by 2002:a81:4e0b:0:b0:577:373b:b18c with SMTP id c11-20020a814e0b000000b00577373bb18cmr12334205ywb.38.1689012416282; Mon, 10 Jul 2023 11:06:56 -0700 (PDT) MIME-Version: 1.0 References: <20230703180528.3709258-1-azeemshaikh38@gmail.com> In-Reply-To: From: Azeem Shaikh Date: Mon, 10 Jul 2023 14:06:44 -0400 Message-ID: Subject: Re: [PATCH] kobject: Replace strlcpy with strscpy To: David Laight Cc: Greg Kroah-Hartman , "linux-hardening@vger.kernel.org" , "Rafael J. Wysocki" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 10, 2023 at 9:13=E2=80=AFAM David Laight wrote: > > > int len; > > > > - len =3D strlcpy(&env->buf[env->buflen], subsystem, buffer_size); > > - if (len >=3D buffer_size) { > > + len =3D strscpy(&env->buf[env->buflen], subsystem, buffer_size); > > + if (len < 0) { > > pr_warn("init_uevent_argv: buffer size of %d too small, n= eeded %d\n", > > buffer_size, len); > > return -ENOMEM; > > The size in the error message is now wrong. Thanks for catching this. > It has to be said that mostly all the strings that get copied > in the kernel are '\0' terminated - so maybe it is all moot. > OTOH printing (at least some of) the string that didn't fit > is a lot more useful than its length. How about printing out strlen(subsystem) along with the entire value of @subsystem? So that the warn reads: pr_warn("init_uevent_argv: buffer size of %d too small for %s, needed %d\n", buffer_size, subsystem, strlen(subsystem)); Does that seem better?