wifi: ath11k: Fix NULL pointer check in ath11k_ce_rx_post_pipe()
PATCH 1/1 wifi: ath11k: Fix NULL pointer check in ath11k_ce_rx_post_pipe()
The previous code used OR for NULL pointer check, whitch can not guarantee the pipe->dest_ring pointer is NON-NULL. When certain errors occur, causing pipe->dest_ring to be NULL while pipe->status_ring remains NON-NULL, the subsequent call to ath11k_ce_rx_buf_enqueue_pipe() will access the NULL pointer, resulting in a driver crash.
If it is assumed that these two pointers will not become NULL for any reason, then only need to check pipe->dest_ring is or not a NULL pointer, and no need to check NULL pointer on pipe->status_ring.
--- drivers/net/wireless/ath/ath11k/ce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath11k/ce.c +1 -1
@@ -324,7 +324,7 @@ static int ath11k_ce_rx_post_pipe(struct ath11k_ce_pipe *pipe)dma_addr_t paddr;int ret =0 ; -if (!(pipe->dest_ring || pipe->status_ring)) +if (!(pipe->dest_ring && pipe->status_ring))return 0 ;spin_lock_bh (&ab->ce.ce_lock);
Signature · 1 line
2.34.1
drivers/net/wireless/ath/ath11k/ce.c static int ath11k_ce_rx_post_pipe(struct ath11k_ce_pipe *pipe) · line 328
Quoted 3 lines · * On 11/25/24 06:08, Baichuan Qi wrote:
drivers/net/wireless/ath/ath11k/ce.c +1
-1-if (!(pipe->dest_ring || pipe->status_ring)) +if (!(pipe->dest_ring && pipe->status_ring))return 0 ;
Wouldn't the expanded form, i.e., if (!pipe->dest_ring || !pipe->status_ring) show the intention more clearly (return if any of these pointers is NULL) and avoid the whole confusion in the first place?
We all know that !(a && b) ~= !a || !b, so your expression is obviously functionally equivalent, but it's not exactly obvious at first glance.
Mihai
thanks for your reply
Quoted 1 line
!(pipe->dest_ring &&
pipe->status_ring)
means both pipe->dest_ring and pipe->status_ring must be NON-NULL , previous code means ONE of these two rings is NON-NULL.
So when some errors happen , dest_ring is NULL and status_ring is NON-NULL , the subsequent call to ath11k_ce_rx_buf_enqueue_pipe() will access the NULL pointer
Baichuan Qi
Quoted 6 lines · * On 11/25/24 08:37, Baichuan Qi wrote:
thanks for your reply
Quoted 1 line
!(pipe->dest_ring &&
pipe->status_ring)means both
pipe->dest_ringandpipe->status_ringmust be NON-NULL , previous code means ONE of these two rings is NON-NULL.
Yes, I understand that, and I already implied that your fix is fine functionally. I can also spell it out more directly.
However, I do believe that !pipe->dest_ring || !pipe->status_ring - which is functionally equivalent to !(pipe->dest_ring && pipe->status_ring) - is more maintainable and easier to parse for humans because it conveys what is meant better at a glance - namely that we want to handle the situation as an error if any of the given pointers is NULL.
Mihai
Quoted 1 line
The previous code used OR for NULL pointer check, whitch can not
…
which?
You may occasionally put more than 64 characters into text lines for an improved change description.
Regards,
Markus
PATCH 1/1 wifi: ath11k: Fix NULL pointer check in ath11k_ce_rx_post_pipe()
Change the OR to AND.
The previous code used OR within parentheses to check for NON-NULL pointer on one of pipe->dest_ring and pipe->status_ring. The previous code can not guarantee the pipe->dest_ring pointer is NON-NULL. When certain errors occur, causing pipe->dest_ring to be NULL while pipe->status_ring remains NON-NULL , the subsequent call to ath11k_ce_rx_buf_enqueue_pipe() will access the NULL pointer, resulting in a driver crash. If it is assumed that these two pointers will not become NULL for any reason , then only need to check pipe->dest_ring is or not a NULL pointer, and no need to check NULL pointer on pipe->status_ring.
--- drivers/net/wireless/ath/ath11k/ce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath11k/ce.c +1 -1
@@ -324,7 +324,7 @@ static int ath11k_ce_rx_post_pipe(struct ath11k_ce_pipe *pipe)dma_addr_t paddr;int ret =0 ; -if (!(pipe->dest_ring || pipe->status_ring)) +if (!(pipe->dest_ring && pipe->status_ring))return 0 ;spin_lock_bh (&ab->ce.ce_lock);
Signature · 1 line
2.34.1
Quoted 2 lines
Change the OR to AND.
The previous code …
I would appreciate further improvements for the change description.
* How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.12#n145
* See also:
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
…
drivers/net/wireless/ath/ath11k/ce.c static int ath11k_ce_rx_post_pipe(struct ath11k_ce_pipe *pipe) · line 328
Quoted 8 lines
+++
b/drivers/net/wireless/ath/ath11k/ce.cdrivers/net/wireless/ath/ath11k/ce.c +1
-1@@ -324,7 +324,7 @@ static int ath11k_ce_rx_post_pipe(struct ath11k_ce_pipe *pipe)dma_addr_t paddr;int ret =0 ; -if (!(pipe->dest_ring || pipe->status_ring)) +if (!(pipe->dest_ring && pipe->status_ring))return 0 ;
…
Is there a need to reconsider also such a return value?
Regards,
Markus
thanks for your reply
Quoted 1 line
Is there a need to reconsider also such a return value?
According to the current code (commit d5c65159f289) of this function, this function should be terminated directly after checking the null pointer, the return value may be meaningless.
Baichuan Qi
Quoted 6 lines
Quoted 1 line
Is there a need to reconsider also such a return value?
According to the current code (commit
d5c65159f289) of this function, this function should be terminated directly after checking the null pointer, the return value may be meaningless.
The return value is checked at two source code places at least.
* ath11k_ce_recv_process_cb():
https://elixir.bootlin.com/linux/v6.12.1/source/drivers/net/wireless/ath/ath11k/ce.c#L450
* ath11k_ce_rx_post_buf():
https://elixir.bootlin.com/linux/v6.12.1/source/drivers/net/wireless/ath/ath11k/ce.c#L893
May the detection of a null pointer for the data structure members “dest_ring” or “status_ring” really be interpreted as a successful execution of the function “ath11k_ce_rx_post_pipe”?
Regards,
Markus
Re: Re: wifi: ath11k: Fix NULL pointer check in ath11k_ce_rx_post_pipe() ERROR code
thanks for your reply
Quoted 3 lines
May the detection of a null pointer for the data structure members “dest_ring” or “status_ring” really be interpreted as a successful execution of the function “ath11k_ce_rx_post_pipe”?
i submit this patch just want to ensure the last codes after if(...) in ath11k_ce_rx_post_pipe can be successfully executed.
There is no error handling for NULL dest_ring (or status_ring) in other funtions calling ath11k_ce_rx_post_pipe(), because it would return 0, like successful end.
I think this patch can not change so many codes in other functions in ce. This may involve a lot of error handling operations, and depending on the severity of situation, the driver may even re_setup the ring.
I will submit a v5 patch, and in that patch an error code will be returned.
Baichuan Qi
PATCH v5 1/1 wifi: ath11k: Fix NULL pointer check in ath11k_ce_rx_post_pipe()
In reply to Markus ElfringCurrent implementation of ath11k_ce_rx_post_pipe() checks for NON-NULL of either dest_ring or status_ring using an OR (||). Both rings, especially dest_ring, should be ensured to be NON-NULL in this function.
If only one of the rings is valid, such as dest_ring is NULL and status_ring is NON-NULL, the OR (||) check would not stop ath11k_ce_rx_post_pipe(), the subsequent call to ath11k_ce_rx_buf_enqueue_pipe() will access the NULL pointer, resulting in a driver crash.
Fix the NON-NULL check by changing the OR (||) to AND (&&), and return an error code -EIO to indicate ath11k_ce_rx_post_pipe() is stopped with an NULL pointer error, ensuring that the function only proceeds when both dest_ring and status_ring are NON-NULL.
---
V4 -> V5: add err code in NULL check
V3 -> V4: reorder describe info
V2 -> V3: add Link URL to mailing list archives
V1 -> V2: rewrite commit message and fix tag
drivers/net/wireless/ath/ath11k/ce.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath11k/ce.c +4 -2
@@ -324,8 +324,10 @@ static int ath11k_ce_rx_post_pipe(struct ath11k_ce_pipe *pipe)dma_addr_t paddr;int ret =0 ; -if (!(pipe->dest_ring || pipe->status_ring)) -return 0 ; +if (!(pipe->dest_ring && pipe->status_ring)) { + ret = -EIO ; +return ret; + }spin_lock_bh (&ab->ce.ce_lock);while (pipe->rx_buf_needed) {
Signature · 1 line
2.34.1
Quoted 11 lines · Baichuan Qi
Current implementation of
ath11k_ce_rx_post_pipe()checks for NON-NULL of eitherdest_ringorstatus_ringusing an OR (||). Both rings, especiallydest_ring, should be ensured to be NON-NULL in this function.If only one of the rings is valid, such as
dest_ringis NULL andstatus_ringis NON-NULL, the OR (||) check would not stopath11k_ce_rx_post_pipe(), the subsequent call toath11k_ce_rx_buf_enqueue_pipe()will access the NULL pointer, resulting in a driver crash.
Quoted 8 lines
Fix the NON-NULL check by changing the OR (||) to AND (&&), and return an error code
-EIOto indicateath11k_ce_rx_post_pipe()is stopped with an NULL pointer error, ensuring that the function only proceeds when bothdest_ringandstatus_ringare NON-NULL.Fixes d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices")
This does not really fix any real issue. Please check ath11k_ce_alloc_pipe() where initialization would fail if anyone of pipe->dest_ring and pipe->status_ring allocation fails for ce pipe used for Rx.
Quoted 15 lines
Signed-off-by Baichuan Qi <[email protected]>---
V4 -> V5: add err code in NULL check
V3 -> V4: reorder describe info
V2 -> V3: add Link URL to mailing list archives
V1 -> V2: rewrite commit message and fix tagdrivers/net/wireless/ath/ath11k/ce.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/net/wireless/ath/ath11k/ce.c +0
-0
drivers/net/wireless/ath/ath11k/ce.c static int ath11k_ce_rx_post_pipe(struct ath11k_ce_pipe *pipe) · line 330
Quoted 9 lines
drivers/net/wireless/ath/ath11k/ce.c +4
-2@@ -324,8 +324,10 @@ static int ath11k_ce_rx_post_pipe(struct ath11k_ce_pipe *pipe)dma_addr_t paddr;int ret =0 ; -if (!(pipe->dest_ring || pipe->status_ring)) -return 0 ; +if (!(pipe->dest_ring && pipe->status_ring)) { + ret = -EIO ; +return ret; + }
This will always fail as the caller loops through all the supported ce pipes and ce pipes used for Tx will not have either dest_ring or status_ring. Please ensure the patch is tested properly.
So NAK
Vasanth
Re: Re: [PATCH v5] NAK
Thanks for your reply
The reason I submit this patch is that the current ath11k_ce_rx_post_pipe() NULL pointer check does not ensure that dest_ring is NON-NULL. And it is not clear to show the filtering of tx ce pipes
Quoted 3 lines
This does not really fix any real issue. Please check
ath11k_ce_alloc_pipe()where initialization would fail if anyone ofpipe->dest_ringandpipe->status_ringallocation fails for ce pipe used for Rx.
When the driver is running normally, the results of the following three are equal:
---
(pipe->dest_ring || pipe->status_ring) // current code (pipe->dest_ring && pipe->status_ring) (pipe->dest_ring)
---
However, when some errors occur and dest_ring is abnormal, the OR operation cannot guarantee that the pointer is NON-NULL.
Quoted 3 lines
This will always fail as the caller loops through all the supported ce pipes and ce pipes used for Tx will not have either
dest_ringorstatus_ring. Please ensure the patch is tested properly.
I tested [PATCH v5] and indeed the wrong return value will lead to wrong results when the pointer is null.
Please refer to [PATCH v4].
Although it does not return an error code, it can ensure that when an unknown error occurs and causes the status of dest_ring and status_ring to be different, the subsequent code will not access the null pointer, which will only cause the driver to fall into loops.
Thanks for you read.
Thanks
Baichuan Qi
PATCH v2 1/1 wifi: ath11k: Fix NULL pointer check in ath11k_ce_rx_post_pipe()
In reply to Markus ElfringThis patch fixes the NON-NULL check by changing the OR (||) to AND (&&), ensuring that the function only proceeds when both dest_ring and status_ring are NON-NULL.
The current implementation of ath11k_ce_rx_post_pipe checks for NON-NULL of either dest_ring or status_ring using a logical OR (||). However, both rings, especially dest_ring, should be ensured to be NON-NULL in this function.
If only one of the rings is valid, such as dest_ring is NULL and status_ring is NON-NULL, the subsequent call to ath11k_ce_rx_buf_enqueue_pipe() will access the NULL pointer, resulting in a driver crash.
--- drivers/net/wireless/ath/ath11k/ce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath11k/ce.c +1 -1
@@ -324,7 +324,7 @@ static int ath11k_ce_rx_post_pipe(struct ath11k_ce_pipe *pipe)dma_addr_t paddr;int ret =0 ; -if (!(pipe->dest_ring || pipe->status_ring)) +if (!(pipe->dest_ring && pipe->status_ring))return 0 ;spin_lock_bh (&ab->ce.ce_lock);
Signature · 1 line
2.34.1
Quoted 4 lines
This patch fixes the NON-NULL check by …
--- drivers/net/wireless/ath/ath11k/ce.c | 2 +-
…
Did you overlook any guidance once more?
See also:
* https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
Regards,
Markus
PATCH v3 1/1 wifi: ath11k: Fix NULL pointer check in ath11k_ce_rx_post_pipe()
Fix the NON-NULL check by changing the OR (||) to AND (&&), ensuring that the function only proceeds when both dest_ring and status_ring are NON-NULL.
The current implementation of ath11k_ce_rx_post_pipe checks for NON-NULL of either dest_ring or status_ring using a logical OR (||). However, both rings, especially dest_ring, should be ensured to be NON-NULL in this function.
If only one of the rings is valid, such as dest_ring is NULL and status_ring is NON-NULL, the subsequent call to ath11k_ce_rx_buf_enqueue_pipe() will access the NULL pointer, resulting in a driver crash.
--- drivers/net/wireless/ath/ath11k/ce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath11k/ce.c +1 -1
@@ -324,7 +324,7 @@ static int ath11k_ce_rx_post_pipe(struct ath11k_ce_pipe *pipe)dma_addr_t paddr;int ret =0 ; -if (!(pipe->dest_ring || pipe->status_ring)) +if (!(pipe->dest_ring && pipe->status_ring))return 0 ;spin_lock_bh (&ab->ce.ce_lock);
Signature · 1 line
2.34.1
Quoted 13 lines · Baichuan Qi
Fix the NON-NULL check by changing the OR (||) to AND (&&), ensuring that the function only proceeds when both
dest_ringandstatus_ringare NON-NULL.The current implementation of
ath11k_ce_rx_post_pipechecks for NON-NULL of eitherdest_ringorstatus_ringusing a logical OR (||). However, both rings, especiallydest_ring, should be ensured to be NON-NULL in this function.
If only one of the rings is valid, such asdest_ringis NULL andstatus_ringis NON-NULL, the subsequent call toath11k_ce_rx_buf_enqueue_pipe()will access the NULL pointer, resulting in a driver crash.
Quoted 4 lines
Fixes d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices")Signed-off-by Baichuan Qi <[email protected]>---
So this is version 3, please remember adding you version change here🙂:
v3: add link URL.
v2: rewrite commit message, add fix tag.
---
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#backtraces-in-commit-messages
Quoted 16 lines
drivers/net/wireless/ath/ath11k/ce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/wireless/ath/ath11k/ce.c +1
-1@@ -324,7 +324,7 @@ static int ath11k_ce_rx_post_pipe(struct ath11k_ce_pipe *pipe)dma_addr_t paddr;int ret =0 ; -if (!(pipe->dest_ring || pipe->status_ring)) +if (!(pipe->dest_ring && pipe->status_ring))return 0 ;spin_lock_bh (&ab->ce.ce_lock);
thanks for your reply
thanks for your help. With your help and Documentation I now understand how to write patch change logs.
Baichuan Qi
Quoted 1 line
Fix the NON-NULL check by …
How do you think about to reorder any information from paragraphs?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.12#n45
…
Quoted 2 lines
--- drivers/net/wireless/ath/ath11k/ce.c | 2 +-
…
Will you become more familiar with patch version descriptions?
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.12#n310
Regards,
Markus
PATCH v4 1/1 wifi: ath11k: Fix NULL pointer check in ath11k_ce_rx_post_pipe()
Current implementation of ath11k_ce_rx_post_pipe() checks for NON-NULL of either dest_ring or status_ring using an OR (||). Both rings, especially dest_ring, should be ensured to be NON-NULL in this function.
If only one of the rings is valid, such as dest_ring is NULL and status_ring is NON-NULL, the OR (||) check would not stop ath11k_ce_rx_post_pipe(), the subsequent call to ath11k_ce_rx_buf_enqueue_pipe() will access the NULL pointer, resulting in a driver crash.
Fix the NON-NULL check by changing the OR (||) to AND (&&), ensuring that the function only proceeds when both dest_ring and status_ring are NON-NULL.
---
V3 -> V4: reorder describe info
V2 -> V3: add Link URL to mailing list archives
V1 -> V2: rewrite commit message and fix tag
drivers/net/wireless/ath/ath11k/ce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath11k/ce.c +1 -1
@@ -324,7 +324,7 @@ static int ath11k_ce_rx_post_pipe(struct ath11k_ce_pipe *pipe)dma_addr_t paddr;int ret =0 ; -if (!(pipe->dest_ring || pipe->status_ring)) +if (!(pipe->dest_ring && pipe->status_ring))return 0 ;spin_lock_bh (&ab->ce.ce_lock);
Signature · 1 line
2.34.1