Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1310321rdh; Fri, 27 Oct 2023 10:14:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEU1v2ourdDDe6xgXNpmZhfRP9AVOlrNKHB6GoGd7k5wHkZNFuQwcBFo4P7gj45PT26wAfa X-Received: by 2002:a25:6884:0:b0:d9a:c450:91a8 with SMTP id d126-20020a256884000000b00d9ac45091a8mr2963212ybc.63.1698426860425; Fri, 27 Oct 2023 10:14:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698426860; cv=none; d=google.com; s=arc-20160816; b=hR2/Eo+DOdKhGisAAYxx/6CO787vRVEajfJoH01dY4jLxKZhQKjp/SRoNQzh0yAjnq IqKjQHe9Ck6bLWk1fSDw0vlYpsXfR5xpOFjvdZXXMgSmoqQo+wpV8mdqrHfvrhWPcq1L N3PSSZR3q7MYl1xFJocuBm+zQCT3HOtu04k5uwO2qjPCqFKm2wDBug8IBjv6JVq45T5c WyoTZSow3Z7k7EbRxSHwh/qkz8tdI2fWx6boUPycgVe6mvnthEJnWPjiiDInK1GnPBBT l9A2d2aqbuZqqdei92IDG8Ve73xqjupDYeGRmU4uBINzDfXZ9K0byTQkk/eunA4SAIi9 5VWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=qDChCAhWfP2NEsM8ZYVimDyS5Pw7pke0+3Lwstcd5JE=; fh=V8Y0U4R+ftzxxP7wYVJlGxUbJnnUy+jLdZpK5du0I8k=; b=sSiF8Qs8a2qgLySm/RZ4E/wKh+sfxhMX5+i6oFRLt8G4LNuGIOyhLvU5Xbe3/4IDvt lTj/UiWbcz2pl86ZJMoYKSzkRzaxs9gET0zYZdNB+neknVQj4izbhyjNryJOKIszYP5/ 0xxurjSzU7GhPG8h0yZobB6o4k/6pPPnrW39JPTp7MtzdvIQ0UWVifwiIDA4KpjPZKTe h5B2dwQt833efIlmeqsZo0D2gJo9v/a+QvWcEbpKm1d2RmIQUYkWXyaec1OnAr1aaLEQ XZJt1o5ATa+9KKpnB9F2djJLC7GNqOepdu38VM3vh/qG1ESw90/TWxAXtlybxC0ieDkM s4Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Psc4K6Dk; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id b145-20020a25cb97000000b00d9a56bfe8c9si3845985ybg.418.2023.10.27.10.14.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 10:14:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Psc4K6Dk; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 3B1D8832DCD6; Fri, 27 Oct 2023 10:14:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232430AbjJ0RN4 (ORCPT + 52 others); Fri, 27 Oct 2023 13:13:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231649AbjJ0RNz (ORCPT ); Fri, 27 Oct 2023 13:13:55 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20C97825B; Fri, 27 Oct 2023 10:13:52 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FE27C433C8; Fri, 27 Oct 2023 17:13:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698426831; bh=KPuRo2bnfsBHo258rZKMPIKg4rb/dKZ3sHungljB//Y=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Psc4K6DkTgjU7sQjh0LKAgyBoU4EP44IST1Qj8iM1j2SrrfQB/IZcy1PuxIaRqId0 ET8plrgucvcgH2OoPjDkVdOdFWy8oqrzVtKvEjAyOSy0viUrKnnbBpoLasmhTI7afJ 81dJQvRBwnLSP5GBjAViUFg+3oB8wmaXkht8b28T6dkUB/ko4u3vOXqsFipahmIA1m 7i7kiG0W85z0IND+5c0CsZU0exVTJ5jU4whCcgNsiWYnq1fxieeHDxyoflgDF0eJOZ TvD3SlhkwbCumwhXxUaiuSLyogvvgi2u/GSmPzioZqGfsLtzsqNDG08AQ1/kl68ezH u41JYh4npAOHg== From: Kalle Valo To: Kees Cook Cc: Justin Stitt , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2] airo: replace deprecated strncpy with strscpy_pad References: <20231026-strncpy-drivers-net-wireless-cisco-airo-c-v2-1-413427249e47@google.com> <202310270859.8EB5599A@keescook> Date: Fri, 27 Oct 2023 20:13:48 +0300 In-Reply-To: <202310270859.8EB5599A@keescook> (Kees Cook's message of "Fri, 27 Oct 2023 08:59:32 -0700") Message-ID: <87h6mcvvhv.fsf@kernel.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 groat.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 (groat.vger.email [0.0.0.0]); Fri, 27 Oct 2023 10:14:05 -0700 (PDT) Kees Cook writes: > On Thu, Oct 26, 2023 at 11:19:18PM +0000, Justin Stitt wrote: > >> strncpy() is deprecated for use on NUL-terminated destination strings >> [1] and as such we should prefer more robust and less ambiguous string >> interfaces. >> >> `extra` is clearly supposed to be NUL-terminated which is evident by the >> manual NUL-byte assignment as well as its immediate usage with strlen(). >> >> Moreover, let's NUL-pad since there is deliberate effort (48 instances) >> made elsewhere to zero-out buffers in these getters and setters: >> 6050 | memset(local->config.nodeName, 0, sizeof(local->config.nodeName)); >> 6130 | memset(local->config.rates, 0, 8); >> 6139 | memset(local->config.rates, 0, 8); >> 6414 | memset(key.key, 0, MAX_KEY_SIZE); >> 6497 | memset(extra, 0, 16); >> (to be clear, strncpy also NUL-padded -- we are matching that behavior) >> >> Considering the above, a suitable replacement is `strscpy_pad` due to >> the fact that it guarantees both NUL-termination and NUL-padding on the >> destination buffer. >> >> We can also replace the hard-coded size of "16" to IW_ESSID_MAX_SIZE >> because this function is a wext handler. >> >> In wext-core.c we have: >> static const struct iw_ioctl_description standard_ioctl[] = { >> ... >> [IW_IOCTL_IDX(SIOCGIWNICKN)] = { >> .header_type = IW_HEADER_TYPE_POINT, >> .token_size = 1, >> .max_tokens = IW_ESSID_MAX_SIZE, >> }, >> >> So the buffer size is (strangely) IW_ESSID_MAX_SIZE >> >> 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 good; thanks! > > Reviewed-by: Kees Cook BTW most likely next week this driver and a bunch of other ancient drivers will removed: https://patchwork.kernel.org/project/linux-wireless/list/?series=795639&state=*&order=date So to avoid unnecessary work on already removed drivers I recommend using wireless-next as the baseline for wireless patches. Though I'm still planning to apply this patch in case we ever add the driver back (I hope not). -- https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches