ath10k.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] wifi: ath10k: replace deprecated strncpy with memcpy
@ 2023-10-24 17:42 Justin Stitt
  2023-10-24 18:14 ` Jeff Johnson
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Justin Stitt @ 2023-10-24 17:42 UTC (permalink / raw)
  To: Kalle Valo, Jeff Johnson
  Cc: ath10k, linux-wireless, linux-kernel, linux-hardening, Justin Stitt

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. Make this explicit with __nonstring and use a plain old
memcpy.

This is also consistent with future copies into arvif->u.ap.ssid:

	if (changed & BSS_CHANGED_SSID &&
	    vif->type == NL80211_IFTYPE_AP) {
		arvif->u.ap.ssid_len = vif->cfg.ssid_len;
		if (vif->cfg.ssid_len)
			memcpy(arvif->u.ap.ssid, vif->cfg.ssid,
			       vif->cfg.ssid_len);
		arvif->u.ap.hidden_ssid = info->hidden_ssid;
	}

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 <justinstitt@google.com>
---
Changes in v2:
- update subject to include wifi
- prefer memcpy() over strtomem() (thanks Kalle, Jeff)
- rebase onto 6.6-rc7 @d88520ad73b79e71
- Link to v1: https://lore.kernel.org/r/20231013-strncpy-drivers-net-wireless-ath-ath10k-mac-c-v1-1-24e40201afa3@google.com
---
Note: build-tested only.

Found with: $ rg "strncpy\("
---
 drivers/net/wireless/ath/ath10k/core.h | 2 +-
 drivers/net/wireless/ath/ath10k/mac.c  | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h
index 4b5239de4018..ba9795a8378a 100644
--- a/drivers/net/wireless/ath/ath10k/core.h
+++ b/drivers/net/wireless/ath/ath10k/core.h
@@ -607,7 +607,7 @@ struct ath10k_vif {
 			u8 tim_bitmap[64];
 			u8 tim_len;
 			u32 ssid_len;
-			u8 ssid[IEEE80211_MAX_SSID_LEN];
+			u8 ssid[IEEE80211_MAX_SSID_LEN] __nonstring;
 			bool hidden_ssid;
 			/* P2P_IE with NoA attribute for P2P_GO case */
 			u32 noa_len;
diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
index 03e7bc5b6c0b..f3f6deb354c6 100644
--- a/drivers/net/wireless/ath/ath10k/mac.c
+++ b/drivers/net/wireless/ath/ath10k/mac.c
@@ -6125,9 +6125,8 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
 
 		if (ieee80211_vif_is_mesh(vif)) {
 			/* mesh doesn't use SSID but firmware needs it */
-			strncpy(arvif->u.ap.ssid, "mesh",
-				sizeof(arvif->u.ap.ssid));
 			arvif->u.ap.ssid_len = 4;
+			memcpy(arvif->u.ap.ssid, "mesh", arvif->u.ap.ssid_len);
 		}
 	}
 

---
base-commit: d88520ad73b79e71e3ddf08de335b8520ae41c5c
change-id: 20231013-strncpy-drivers-net-wireless-ath-ath10k-mac-c-c73a55666e6a

Best regards,
--
Justin Stitt <justinstitt@google.com>


_______________________________________________
ath10k mailing list
ath10k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath10k

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] wifi: ath10k: replace deprecated strncpy with memcpy
  2023-10-24 17:42 [PATCH v2] wifi: ath10k: replace deprecated strncpy with memcpy Justin Stitt
@ 2023-10-24 18:14 ` Jeff Johnson
  2023-10-24 21:34 ` Kees Cook
  2023-10-31  7:46 ` Kalle Valo
  2 siblings, 0 replies; 5+ messages in thread
From: Jeff Johnson @ 2023-10-24 18:14 UTC (permalink / raw)
  To: Justin Stitt, Kalle Valo
  Cc: ath10k, linux-wireless, linux-kernel, linux-hardening

On 10/24/2023 10:42 AM, 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. Make this explicit with __nonstring and use a plain old
> memcpy.
> 
> This is also consistent with future copies into arvif->u.ap.ssid:
> 
> 	if (changed & BSS_CHANGED_SSID &&
> 	    vif->type == NL80211_IFTYPE_AP) {
> 		arvif->u.ap.ssid_len = vif->cfg.ssid_len;
> 		if (vif->cfg.ssid_len)
> 			memcpy(arvif->u.ap.ssid, vif->cfg.ssid,
> 			       vif->cfg.ssid_len);
> 		arvif->u.ap.hidden_ssid = info->hidden_ssid;
> 	}
> 
> 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 <justinstitt@google.com>
Acked-by: Jeff Johnson <quic_jjohnson@quicinc.com>


_______________________________________________
ath10k mailing list
ath10k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath10k

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] wifi: ath10k: replace deprecated strncpy with memcpy
  2023-10-24 17:42 [PATCH v2] wifi: ath10k: replace deprecated strncpy with memcpy Justin Stitt
  2023-10-24 18:14 ` Jeff Johnson
@ 2023-10-24 21:34 ` Kees Cook
  2023-10-24 23:19   ` Jeff Johnson
  2023-10-31  7:46 ` Kalle Valo
  2 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2023-10-24 21:34 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Kalle Valo, Jeff Johnson, ath10k, linux-wireless, linux-kernel,
	linux-hardening

On Tue, Oct 24, 2023 at 05:42:16PM +0000, 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. Make this explicit with __nonstring and use a plain old
> memcpy.
> 
> This is also consistent with future copies into arvif->u.ap.ssid:
> 
> 	if (changed & BSS_CHANGED_SSID &&
> 	    vif->type == NL80211_IFTYPE_AP) {
> 		arvif->u.ap.ssid_len = vif->cfg.ssid_len;
> 		if (vif->cfg.ssid_len)
> 			memcpy(arvif->u.ap.ssid, vif->cfg.ssid,
> 			       vif->cfg.ssid_len);
> 		arvif->u.ap.hidden_ssid = info->hidden_ssid;
> 	}
> 
> 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 <justinstitt@google.com>
> ---
> Changes in v2:
> - update subject to include wifi
> - prefer memcpy() over strtomem() (thanks Kalle, Jeff)
> - rebase onto 6.6-rc7 @d88520ad73b79e71
> - Link to v1: https://lore.kernel.org/r/20231013-strncpy-drivers-net-wireless-ath-ath10k-mac-c-v1-1-24e40201afa3@google.com
> ---
> Note: build-tested only.
> 
> Found with: $ rg "strncpy\("
> ---
>  drivers/net/wireless/ath/ath10k/core.h | 2 +-
>  drivers/net/wireless/ath/ath10k/mac.c  | 3 +--
>  2 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h
> index 4b5239de4018..ba9795a8378a 100644
> --- a/drivers/net/wireless/ath/ath10k/core.h
> +++ b/drivers/net/wireless/ath/ath10k/core.h
> @@ -607,7 +607,7 @@ struct ath10k_vif {
>  			u8 tim_bitmap[64];
>  			u8 tim_len;
>  			u32 ssid_len;
> -			u8 ssid[IEEE80211_MAX_SSID_LEN];
> +			u8 ssid[IEEE80211_MAX_SSID_LEN] __nonstring;
>  			bool hidden_ssid;
>  			/* P2P_IE with NoA attribute for P2P_GO case */
>  			u32 noa_len;
> diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
> index 03e7bc5b6c0b..f3f6deb354c6 100644
> --- a/drivers/net/wireless/ath/ath10k/mac.c
> +++ b/drivers/net/wireless/ath/ath10k/mac.c
> @@ -6125,9 +6125,8 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
>  
>  		if (ieee80211_vif_is_mesh(vif)) {
>  			/* mesh doesn't use SSID but firmware needs it */
> -			strncpy(arvif->u.ap.ssid, "mesh",
> -				sizeof(arvif->u.ap.ssid));
>  			arvif->u.ap.ssid_len = 4;
> +			memcpy(arvif->u.ap.ssid, "mesh", arvif->u.ap.ssid_len);

This is a behavior change, isn't it? i.e. arvif->u.ap.ssid is no longer
zero-padded. Is this actually ok for the driver?

-Kees

-- 
Kees Cook

_______________________________________________
ath10k mailing list
ath10k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath10k

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] wifi: ath10k: replace deprecated strncpy with memcpy
  2023-10-24 21:34 ` Kees Cook
@ 2023-10-24 23:19   ` Jeff Johnson
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff Johnson @ 2023-10-24 23:19 UTC (permalink / raw)
  To: Kees Cook, Justin Stitt
  Cc: Kalle Valo, ath10k, linux-wireless, linux-kernel, linux-hardening

On 10/24/2023 2:34 PM, Kees Cook wrote:
> On Tue, Oct 24, 2023 at 05:42:16PM +0000, 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. Make this explicit with __nonstring and use a plain old
>> memcpy.
>>
>> This is also consistent with future copies into arvif->u.ap.ssid:
>>
>> 	if (changed & BSS_CHANGED_SSID &&
>> 	    vif->type == NL80211_IFTYPE_AP) {
>> 		arvif->u.ap.ssid_len = vif->cfg.ssid_len;
>> 		if (vif->cfg.ssid_len)
>> 			memcpy(arvif->u.ap.ssid, vif->cfg.ssid,
>> 			       vif->cfg.ssid_len);
>> 		arvif->u.ap.hidden_ssid = info->hidden_ssid;
>> 	}
>>
>> 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 <justinstitt@google.com>
>> ---
>> Changes in v2:
>> - update subject to include wifi
>> - prefer memcpy() over strtomem() (thanks Kalle, Jeff)
>> - rebase onto 6.6-rc7 @d88520ad73b79e71
>> - Link to v1: https://lore.kernel.org/r/20231013-strncpy-drivers-net-wireless-ath-ath10k-mac-c-v1-1-24e40201afa3@google.com
>> ---
>> Note: build-tested only.
>>
>> Found with: $ rg "strncpy\("
>> ---
>>   drivers/net/wireless/ath/ath10k/core.h | 2 +-
>>   drivers/net/wireless/ath/ath10k/mac.c  | 3 +--
>>   2 files changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h
>> index 4b5239de4018..ba9795a8378a 100644
>> --- a/drivers/net/wireless/ath/ath10k/core.h
>> +++ b/drivers/net/wireless/ath/ath10k/core.h
>> @@ -607,7 +607,7 @@ struct ath10k_vif {
>>   			u8 tim_bitmap[64];
>>   			u8 tim_len;
>>   			u32 ssid_len;
>> -			u8 ssid[IEEE80211_MAX_SSID_LEN];
>> +			u8 ssid[IEEE80211_MAX_SSID_LEN] __nonstring;
>>   			bool hidden_ssid;
>>   			/* P2P_IE with NoA attribute for P2P_GO case */
>>   			u32 noa_len;
>> diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
>> index 03e7bc5b6c0b..f3f6deb354c6 100644
>> --- a/drivers/net/wireless/ath/ath10k/mac.c
>> +++ b/drivers/net/wireless/ath/ath10k/mac.c
>> @@ -6125,9 +6125,8 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
>>   
>>   		if (ieee80211_vif_is_mesh(vif)) {
>>   			/* mesh doesn't use SSID but firmware needs it */
>> -			strncpy(arvif->u.ap.ssid, "mesh",
>> -				sizeof(arvif->u.ap.ssid));
>>   			arvif->u.ap.ssid_len = 4;
>> +			memcpy(arvif->u.ap.ssid, "mesh", arvif->u.ap.ssid_len);
> 
> This is a behavior change, isn't it? i.e. arvif->u.ap.ssid is no longer
> zero-padded. Is this actually ok for the driver?

yes, it is safe, and consistent with other uses of this field as noted 
in the commit description.


_______________________________________________
ath10k mailing list
ath10k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath10k

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] wifi: ath10k: replace deprecated strncpy with memcpy
  2023-10-24 17:42 [PATCH v2] wifi: ath10k: replace deprecated strncpy with memcpy Justin Stitt
  2023-10-24 18:14 ` Jeff Johnson
  2023-10-24 21:34 ` Kees Cook
@ 2023-10-31  7:46 ` Kalle Valo
  2 siblings, 0 replies; 5+ messages in thread
From: Kalle Valo @ 2023-10-31  7:46 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Jeff Johnson, ath10k, linux-wireless, linux-kernel,
	linux-hardening, Justin Stitt

Justin Stitt <justinstitt@google.com> 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. Make this explicit with __nonstring and use a plain old
> memcpy.
> 
> This is also consistent with future copies into arvif->u.ap.ssid:
> 
>         if (changed & BSS_CHANGED_SSID &&
>             vif->type == NL80211_IFTYPE_AP) {
>                 arvif->u.ap.ssid_len = vif->cfg.ssid_len;
>                 if (vif->cfg.ssid_len)
>                         memcpy(arvif->u.ap.ssid, vif->cfg.ssid,
>                                vif->cfg.ssid_len);
>                 arvif->u.ap.hidden_ssid = info->hidden_ssid;
>         }
> 
> 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 <justinstitt@google.com>
> Acked-by: Jeff Johnson <quic_jjohnson@quicinc.com>
> Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>

Patch applied to ath-next branch of ath.git, thanks.

ac2f43d3d34e wifi: ath10k: replace deprecated strncpy with memcpy

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/20231024-strncpy-drivers-net-wireless-ath-ath10k-mac-c-v2-1-4c1f4cd4b4df@google.com/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


_______________________________________________
ath10k mailing list
ath10k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath10k

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-31  7:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-24 17:42 [PATCH v2] wifi: ath10k: replace deprecated strncpy with memcpy Justin Stitt
2023-10-24 18:14 ` Jeff Johnson
2023-10-24 21:34 ` Kees Cook
2023-10-24 23:19   ` Jeff Johnson
2023-10-31  7:46 ` Kalle Valo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).