Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp21355rdb; Wed, 18 Oct 2023 16:35:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHokaxWi+oIcXmB2o/UfOMnVtsGszjsXE3xgpZuR9+ZLWu3i2Ab3FgADXw4YLlPzoV6hJIe X-Received: by 2002:a17:903:2890:b0:1c9:e2ed:66fe with SMTP id ku16-20020a170903289000b001c9e2ed66femr756656plb.52.1697672158079; Wed, 18 Oct 2023 16:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697672158; cv=none; d=google.com; s=arc-20160816; b=OfRhLEWEtHV0GGiu+89cJFwtN+NS7SsThmsNvMmMKRLCWPXaCCbhu9qZKPCN2paaan ffnva2W1L5OtAebTC/UE5SBQsvw6g0cwLhIuLX+YV9VgiXhZh8p1frgIVi+HGMzEI7j1 g75j1G6inXadQ13IHK1hs8ctL6Pq/AYRCwROtWuId5JCHYzQh1tTQ5NonLC36N2YPiDN g1MeD7K5HpjfBIapLoPl+TkpN95e7tE3RcWjJiz/o6JhnYvJfz048Uas+rEr2M79VoqB YuF7PUxfOpQJsKLtFyLGyfgYj/+TAEOGY5Uw21oHSIB6d+lYnOARsEySzJnjRDtGHXeH YXLQ== 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=xxRMOhkHfqF2Yz4cAD/a2m3hMjCZwz0gsRF0WfVLtiE=; fh=VSE1H8cDxLaFunyyPaaEex8PW6bZ8md6zggLY0swrAw=; b=u18XhiX1QWuKFhdYADGYNZ0ifNw2aY2mRfweN/YdyG57Rp7r/A0mDoafLDA+geGU9M B4zcJ8uqWvEsfkWVBCw7cIwS8HmPpex23OjWYO19BfT4bECYRfcNO6qstxfr1pGqr9yF +6C+J7u12kQdKmcSoUv7RXts0TMLNm064nj/04rdN5+HitjSdDMFCntoIK6CoiC3a0J0 5CBRY4SQcoPlgCShkf9L1u2iZpliagddHC/fTBBS+mJM2FZVcQsPsfVb3mpbaUha0e7g NQp+a/kfrTyvCZi6XXPVoky0TR7VPH+CYz4qbJ+07FG4D4cO7/RLTbH1bvTjb4aC9leW ptzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BjWFbYah; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id k9-20020a170902694900b001c9c8e0cbafsi851803plt.202.2023.10.18.16.35.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:35:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BjWFbYah; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-wireless-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 morse.vger.email (Postfix) with ESMTP id 2D56A80AFE99; Wed, 18 Oct 2023 16:35:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231521AbjJRXfM (ORCPT + 52 others); Wed, 18 Oct 2023 19:35:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229697AbjJRXfL (ORCPT ); Wed, 18 Oct 2023 19:35:11 -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 57EB910F for ; Wed, 18 Oct 2023 16:35:09 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c9bca1d96cso51634345ad.3 for ; Wed, 18 Oct 2023 16:35:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697672109; x=1698276909; 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=xxRMOhkHfqF2Yz4cAD/a2m3hMjCZwz0gsRF0WfVLtiE=; b=BjWFbYahC8O7XRC6DzvorCb+dM3pvf7X0L08LcR0xDolDfiK+MlYyXrpliWGl4qid2 nNKBAQyiJJAliwcHEe5cgl4FtTbPJrMvw4rzQoe7/Ohb/vPADzsD5nLIpum6K99Sg9vD Ilzd+FOC3Hjt/K6UapFQSsb5QbX15vszM+P3U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697672109; x=1698276909; 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=xxRMOhkHfqF2Yz4cAD/a2m3hMjCZwz0gsRF0WfVLtiE=; b=Jv0VRaQHaQvF+oPgvIAACgYjcUMvs+d1IGkvOzeEXOnvfi2tLJ4sS63ZAVqGjvNUka DxeSlUM+JB0YGtJJhwx+nsVb4eoeSOLZrRnE9hni09U/7msE4lvcLudVVRpHCUxMtqEb ZCQgq2vwXwalkAf74u46wK7nuUqLqiuZxj2gF4XOGIi/wOFDuv8PrRO+AKcWijeAmgPj QGmJs4HDWTHurvcNG1A11jSob/7FKh8tIqamrcdSkEEadYJcpSVHxS6bWOssQwkDQrjY 4seZtDXgMsvkvZS/REBrHD2xtcpMOebwuhQSDgZllKKbPRYSCELePekIeMGWFb2oFu+7 9ItQ== X-Gm-Message-State: AOJu0YyOb3HanmCeMiaiSst+c7N4olFrME/RIc0JhbtDrJjQbTwb8cwU sNp9Cb70EtxFZ5CAzjX6W6V3VQ== X-Received: by 2002:a17:902:ec87:b0:1c5:d063:b70e with SMTP id x7-20020a170902ec8700b001c5d063b70emr1020318plg.53.1697672108702; Wed, 18 Oct 2023 16:35:08 -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 f18-20020a170902ce9200b001bc18e579aesm480575plg.101.2023.10.18.16.35.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:35:08 -0700 (PDT) Date: Wed, 18 Oct 2023 16:35:07 -0700 From: Kees Cook To: Jeff Johnson Cc: Justin Stitt , Kalle Valo , ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] ath10k: replace deprecated strncpy with strtomem_pad Message-ID: <202310181626.C5BE0C21F@keescook> References: <20231013-strncpy-drivers-net-wireless-ath-ath10k-mac-c-v1-1-24e40201afa3@google.com> <1cfc7c64-439c-437e-af82-7fce1202242d@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1cfc7c64-439c-437e-af82-7fce1202242d@quicinc.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 morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 18 Oct 2023 16:35:13 -0700 (PDT) On Fri, Oct 13, 2023 at 05:58:03PM -0700, Jeff Johnson wrote: > On 10/13/2023 1:33 PM, Justin Stitt wrote: > > strncpy() is deprecated [1] and we should prefer less ambiguous > > interfaces. > > > > In this case, arvif->u.ap.ssid has its length maintained by > > arvif->u.ap.ssid_len which indicates it may not need to be > > NUL-terminated, although by virtue of using strtomem_pad (with NUL-byte > > pad character) and having a destination size larger than the source, > > ssid will, incidentally, be NUL-terminated here. > > > > As strtomem_pad() docs say: > > * @dest: Pointer of destination character array (marked as __nonstring) > > * @src: Pointer to NUL-terminated string > > * @pad: Padding character to fill any remaining bytes of @dest after copy > > * > > * This is a replacement for strncpy() uses where the destination is not > > * a NUL-terminated string, but with bounds checking on the source size, and > > * an explicit padding character. If padding is not required, use strtomem(). > > > > Let's also mark ath10k_vif.u.ap.ssid as __nonstring. > > what criteria is used to determine whether or not to use __nonstring? > doesn't the use of u8 vs char already communicate that distinction? > just want to know what other u8 arrays might require this. > FWIW the documentation referenced by the __nonstring macro explicitly refers > to "type array of char, signed char, or unsigned char" The use of __nonstring is for byte arrays that are _not_ expected to be %NUL terminated. Unfortunately "char" vs "u8" isn't distinguished by the compiler. All byte arrays are treated as C strings unless __nonstring is used. > > It is unclear to me whether padding is strictly necessary. Perhaps we > > should opt for just strtomem() -- padding certainly doesn't hurt, > > though. > > concur that padding probably isn't necessary but doesn't hurt, and will > prevent confusion if looking at this member in a crashdump > > > > > 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 > > Either with or without the __nonstring... > Acked-by: Jeff Johnson Yup, it looks like the ssid member is passed around with memcpy() everywhere else. Reviewed-by: Kees Cook -- Kees Cook