Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1276176rdh; Fri, 27 Oct 2023 09:19:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4XqerldHA8WyQwLL7vSbGimtbqiAxOWUBPzGTPhnqLjbkqNdYA0D/4+a/H/MX+4voN9A/ X-Received: by 2002:a05:6870:b17:b0:1bb:c0ee:5536 with SMTP id lh23-20020a0568700b1700b001bbc0ee5536mr4093794oab.47.1698423553234; Fri, 27 Oct 2023 09:19:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698423553; cv=none; d=google.com; s=arc-20160816; b=HFcXY5o2ZGsfm4EQuze5szsLsy4IqGZDFBQsVXbgZNTURnfBatb/m/9aNyVkbXoe51 Aqy0kn/aWD1MJvrXDEQULOuwMwaCjXLmXL9UizliIIFzDK39nyC+JZCqLPjuC0fXI8b8 E3K0UWP7sg/YpZYQuN1sJlTvVDBzvagpaz4T8JIW+TMZxdGnENa7R9sj/InZBtlni7mM ScZvPPekJugpP4L8yYBruBCIoD1DHXPzXTVR+/cpnt2jgEnegoPinOL1AS/VMdKmoS1L UigoY7aZgWWYVOp/gXkJavq+umBhc5C8b9Ap0dMYDtPKSO4MSwQJB59c4+A4zejbHVCi HzNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=twpA4kPTjPdlQanwemh5B6a0NpYFUbg/0uFl1vufWFs=; fh=KD/SulqD94brwJZSGPOxU6BgRlr6wg1OBHzzyP23MOQ=; b=YA/OtQHAsSc/cA3X14W7i8YTkCC8xZ4Tf9fZM7OVf6h710Sh/4wZb86mnuYxRsHv5k /mlFNQPPngG6RNoUUbdCGiwNpk/vL3bVtgg323ipPBfFIle0QUTPGCjc6nXijPPO8zrv 14GpUDoW1NrVOCgpyk8LpzGdT1+UtLAeGY3VPNXICxYYVIaTs7rIrBU6G5eIkhSK/ZBB me7veKeWw9tIHkAaJ2TqpuIkxCQXxHSPUQkpqdb6XJuA6j2xzr/DYBBlGVNcmp1jt/uG 7PA4c1+Dfzlcdb+wTwIdzHlw5I/1Sg+vOnpQQz6Tk59w0fu3dUYLKJ8pNRJfCquF7S+j 9QjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OLUjGzOX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id n15-20020a819e4f000000b005a1cd8cecc9si2868315ywj.416.2023.10.27.09.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 09:19:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OLUjGzOX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 268248077831; Fri, 27 Oct 2023 09:19:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231722AbjJ0QTB (ORCPT + 99 others); Fri, 27 Oct 2023 12:19:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230451AbjJ0QTB (ORCPT ); Fri, 27 Oct 2023 12:19:01 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3042106 for ; Fri, 27 Oct 2023 09:18:58 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1ca6809fb8aso18290115ad.1 for ; Fri, 27 Oct 2023 09:18:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1698423538; x=1699028338; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=twpA4kPTjPdlQanwemh5B6a0NpYFUbg/0uFl1vufWFs=; b=OLUjGzOXJ2tw9AcnRVY6HY+c8Xs70HO3JLR2kVvG7dWhrTHHcnUklj2HFTNULvzvwk FhFnjmSeUkeeOmZBO+1x+aRCIsJJyVNdk9+XAdWyO7dBnWuxph23C5AaQ6+ZvYkjKArS lrmeuvubU+EWEmAh6j9xfqWACO8HPnDfb4UkY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698423538; x=1699028338; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=twpA4kPTjPdlQanwemh5B6a0NpYFUbg/0uFl1vufWFs=; b=AueQHwKHiL08Fgh/BtiRWkOqfEVKBYJVCoaxg4pVLpMAauD3GGikJw5XhA25GoxVUf sYLaqZY4ckxw95SU2nLB/EZr2QVHMqA+s2u2z411Wn7FZNsiHnkrnRgH/4atNM8BDX4e lLLXu9R6l7EK8duOYfXYsOpYtrAfQUgJrKjnXDtNDtrgRSJfHlQdymQF0FTqTeXsa6wg 0p1xAFGPSFboYfIkBR7JN0K39sfE/4Cg+Rvu8+adln/hMAhlIKZTAv7o+viMdFDABxbW Xr1tSSuY0IIPqa9G0a9DF6WZEAfDV84n2f2I5lsu1yqBDpibUihvL/C1A7hkylpk1OqM 3gnw== X-Gm-Message-State: AOJu0Yyv1hhP7H8Uje7jovQqGt3rPQKg6vEDkACds0mf3onMMk/yOGne vplX117zR2v5IGA4Trid2dnGzA== X-Received: by 2002:a17:903:2309:b0:1c9:ece9:53d2 with SMTP id d9-20020a170903230900b001c9ece953d2mr3515237plh.61.1698423538314; Fri, 27 Oct 2023 09:18:58 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id z5-20020a170902ee0500b001c625d6ffccsm1759643plb.129.2023.10.27.09.18.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 09:18:57 -0700 (PDT) Date: Fri, 27 Oct 2023 09:18:57 -0700 From: Kees Cook To: Justin Stitt Cc: Jonathan Cameron , Lars-Peter Clausen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2] iio: sx9324: avoid copying property strings Message-ID: <202310270918.EDE919D348@keescook> References: <20231026-strncpy-drivers-iio-proximity-sx9324-c-v2-1-cee6e5db700c@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231026-strncpy-drivers-iio-proximity-sx9324-c-v2-1-cee6e5db700c@google.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 27 Oct 2023 09:19:10 -0700 (PDT) On Thu, Oct 26, 2023 at 11:53:28PM +0000, Justin Stitt wrote: > We're doing some needless string copies when trying to assign the proper > `prop` string. We can make `prop` a const char* and simply assign to > string literals. > > For the case where a format string is used, let's allocate some memory > via kasprintf() and point prop to it. > > This also cleans up some deprecated strncpy() uses [1]. > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] > Link: https://github.com/KSPP/linux/issues/90 > Cc: linux-hardening@vger.kernel.org > Signed-off-by: Justin Stitt Looks like a reasonable way to go. Reviewed-by: Kees Cook -- Kees Cook