Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4927880rdb; Tue, 12 Dec 2023 13:26:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFU472NkS/txULBSnBJkMAwDSWOc7WRUYXuqUzhgzmK+Ee1bhhak9u2NU9R9gvkj5AL/jdc X-Received: by 2002:a05:6a20:7d86:b0:18f:f86f:bcdb with SMTP id v6-20020a056a207d8600b0018ff86fbcdbmr8397906pzj.93.1702416400754; Tue, 12 Dec 2023 13:26:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702416400; cv=none; d=google.com; s=arc-20160816; b=IMoRcbXlnLc8yxxhKRH8kJbXRv92p14Flu4uPfQ2BE9JeYzfGgk1pdjKzB+em0Ro1R mRMkCgsZ91QIf/I+YrLPFH+9cJAyY2M9q12UAJC8rpF+lILN8k+UniTfnInS2LAQJwYF Twnf7vF56UxLPqOsnWwYKEQkAgForM6rY+R/ReWaMA2ihViTTLHl0BZXWOK+ouywoLr2 lnCWm/JhW/k/RZEhaxSyuY/0EimW8nQjzG4eYwt3ZwIQSXKiD34yRb+gNm7clfC0Prhe zr/SSOQ2NlXE7XeaYiEU+BprKm7Dv0rtcfcXm4FQAg+9dTOegeS+IBKY5PVTS47sEgyG kt0A== 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=m5PlYZzo9vfTv/yv9EMUjQKbKWWq7A3gpV1Plw7Ax/Y=; fh=r+GzkyqH8Y3maWEB9nKcgWVW0XDD3AZVo31bLqWiB+Q=; b=fzczlLLrqVJgYUZjQbwxtf1FeofXU0M0aRiEf0+5RGX2OUKuulAPIMLsU+u99/frZC U1WLqpWUgA6BTB2HGxYngfAnVPsOc5wziNMiy5bZ5q12ETJkZkt7ZOLAPNivRRwlF+cB TD0XQUIZnKMIboy54P1ScGr/KNyDtG7LZymonxRAFNrZlXwb+IHbu8LFdSF7EfO9oFMA opW58IHIda6l1kl0UcC0kAikyeebJwv7cOkfOYuo8eKk65v8dwrTmo76GP0z8CfJrWhN chY9Gx1UQMBHcSAnrxX9nsJ2etVWCu0mxE6460xBO7azl0bG0/7NAuWOnVV7yLMY/Ij1 Nm0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KUf5Hivl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id g18-20020a056a000b9200b006cb6b7aa192si8426433pfj.331.2023.12.12.13.26.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 13:26:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KUf5Hivl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 0F56D801E0C2; Tue, 12 Dec 2023 13:26:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377646AbjLLV0Q (ORCPT + 99 others); Tue, 12 Dec 2023 16:26:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377921AbjLLV0K (ORCPT ); Tue, 12 Dec 2023 16:26:10 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80882BD for ; Tue, 12 Dec 2023 13:26:16 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6ce939ecfc2so5578965b3a.2 for ; Tue, 12 Dec 2023 13:26:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1702416376; x=1703021176; 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=m5PlYZzo9vfTv/yv9EMUjQKbKWWq7A3gpV1Plw7Ax/Y=; b=KUf5HivlYL4ctCdp+SW+aRt+SMv/QY70kRXFLFAk41qCRZyj208eQV+tNJTJXFf44N UwWxEFLGWu1UskPYvENoFXxrz2T94Xs/qjlrTN68HVOAKnDaz0SX6oEPcgQD/jVoJnFc v+EfcOAyxQyAUYX/vnRufNDnMY3MVfHf91cq4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702416376; x=1703021176; 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=m5PlYZzo9vfTv/yv9EMUjQKbKWWq7A3gpV1Plw7Ax/Y=; b=OZbyLQZ70T7jBf9k8599BzUq6HnXGWAieGX+DBmQFyBibldASRJEYZckDSm4nEbOp0 fOTXj9FunBXJQPMA5PGWYA2ZpDQgdDqV8n81p5P5pd+bJXTtPobOWJ9k7/YmfAtHP1NF QuU7+o8JBaay4ZyxuaKpUiPg+VzbteOb0VWkljVYi+Bv0vaAEajnmS0etBvLpWk90TEw m/LJQy/GLhHUJmzGv/9GMaS4dbNEA6Rt7+BOyDwN8+cBcGwctmki1vqyniIzjC5pVHiJ heN818ugmd3l+PPL7w+ahezBfPKWZbKOEv3KJq6n/X7nQxrtCtABSBYfUFY+7r1/Iqg/ MaWA== X-Gm-Message-State: AOJu0Yyvg+8Zy2tMkOY/O4juCHrHRzUvCd2Fb5baTqIlE+c81nKNEsE7 R8IMlsky+DyI28Az8B3Axi2Xvg== X-Received: by 2002:a05:6a00:4601:b0:6cd:f91e:dfe4 with SMTP id ko1-20020a056a00460100b006cdf91edfe4mr6874221pfb.2.1702416375774; Tue, 12 Dec 2023 13:26:15 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id d12-20020a056a0010cc00b006ce61c9495fsm8571312pfu.206.2023.12.12.13.26.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 13:26:15 -0800 (PST) Date: Tue, 12 Dec 2023 13:26:14 -0800 From: Kees Cook To: Justin Stitt Cc: Jonathan Cameron , Lars-Peter Clausen , Stephen Boyd , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v3] iio: sx9324: avoid copying property strings Message-ID: <202312121325.E29472E0C0@keescook> References: <20231212-strncpy-drivers-iio-proximity-sx9324-c-v3-1-b8ae12fc8a5d@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231212-strncpy-drivers-iio-proximity-sx9324-c-v3-1-b8ae12fc8a5d@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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Tue, 12 Dec 2023 13:26:38 -0800 (PST) On Tue, Dec 12, 2023 at 12:42:52AM +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 extract the parsing > logic out into sx9324_parse_phase_prop(). We no longer need to create > copies or allocate new memory. > > sx9324_parse_phase_prop() will simply return the default def value if it > fails. > > 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 Yeah, I like this approach. Totally removes the string copying and creates a helper that does the "heavy lifting". :) Reviewed-by: Kees Cook -- Kees Cook