diff mbox series

[v2] Fix NULL pointer deref due to filtering on fork

Message ID 20231011051225.3674436-1-anjali.k.kulkarni@oracle.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [v2] Fix NULL pointer deref due to filtering on fork | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Anjali Kulkarni Oct. 11, 2023, 5:12 a.m. UTC
cn_netlink_send_mult() should be called with filter & filter_data only
for EXIT case. For all other events, filter & filter_data should be
NULL.

Fixes: 2aa1f7a1f47c ("connector/cn_proc: Add filtering to fix some bugs")
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://urldefense.com/v3/__https://lore.kernel.org/oe-lkp/202309201456.84c19e27-oliver.sang@intel.com__;!!ACWV5N9M2RV99hQ!PgqlHq_nOe_KlyKkB9Mm_S8QstTJvicjuENwskatuuQK05KPuFw-KvRZeOH8iuEAMjRhkxEMPKJJnLcaT8zrPf9aqNs$

Signed-off-by: Anjali Kulkarni <anjali.k.kulkarni@oracle.com>
---
 drivers/connector/cn_proc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Simon Horman Oct. 13, 2023, 12:01 p.m. UTC | #1
On Tue, Oct 10, 2023 at 10:12:25PM -0700, Anjali Kulkarni wrote:
> cn_netlink_send_mult() should be called with filter & filter_data only
> for EXIT case. For all other events, filter & filter_data should be
> NULL.
> 
> Fixes: 2aa1f7a1f47c ("connector/cn_proc: Add filtering to fix some bugs")
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Closes: https://urldefense.com/v3/__https://lore.kernel.org/oe-lkp/202309201456.84c19e27-oliver.sang@intel.com__;!!ACWV5N9M2RV99hQ!PgqlHq_nOe_KlyKkB9Mm_S8QstTJvicjuENwskatuuQK05KPuFw-KvRZeOH8iuEAMjRhkxEMPKJJnLcaT8zrPf9aqNs$

For the record, this got a bit mangled. I believe it should be:

Closes: https://lore.kernel.org/oe-lkp/202309201456.84c19e27-oliver.sang@intel.com/

Also, there is probably no need to resend because of this,
but no blank line here, please.

> Signed-off-by: Anjali Kulkarni <anjali.k.kulkarni@oracle.com>
> ---
>  drivers/connector/cn_proc.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
> index 05d562e9c8b1..01e17f18d187 100644
> --- a/drivers/connector/cn_proc.c
> +++ b/drivers/connector/cn_proc.c
> @@ -104,13 +104,13 @@ static inline void send_msg(struct cn_msg *msg)
>  	if (filter_data[0] == PROC_EVENT_EXIT) {
>  		filter_data[1] =
>  		((struct proc_event *)msg->data)->event_data.exit.exit_code;
> +		cn_netlink_send_mult(msg, msg->len, 0, CN_IDX_PROC, GFP_NOWAIT,
> +				     cn_filter, (void *)filter_data);
>  	} else {
> -		filter_data[1] = 0;
> +		cn_netlink_send_mult(msg, msg->len, 0, CN_IDX_PROC, GFP_NOWAIT,
> +				     NULL, NULL);
>  	}
>  
> -	cn_netlink_send_mult(msg, msg->len, 0, CN_IDX_PROC, GFP_NOWAIT,
> -			     cn_filter, (void *)filter_data);
> -

I am wondering if you considered making cn_filter slightly smarter.
It seems it already understands not to do very much for PROC_EVENT_ALL.

>  	local_unlock(&local_event.lock);
>  }
>  
> -- 
> 2.42.0
> 
>
Anjali Kulkarni Oct. 13, 2023, 4:16 p.m. UTC | #2
> On Oct 13, 2023, at 5:01 AM, Simon Horman <horms@kernel.org> wrote:
> 
> On Tue, Oct 10, 2023 at 10:12:25PM -0700, Anjali Kulkarni wrote:
>> cn_netlink_send_mult() should be called with filter & filter_data only
>> for EXIT case. For all other events, filter & filter_data should be
>> NULL.
>> 
>> Fixes: 2aa1f7a1f47c ("connector/cn_proc: Add filtering to fix some bugs")
>> Reported-by: kernel test robot <oliver.sang@intel.com>
>> Closes: https://urldefense.com/v3/__https://lore.kernel.org/oe-lkp/202309201456.84c19e27-oliver.sang@intel.com__;!!ACWV5N9M2RV99hQ!PgqlHq_nOe_KlyKkB9Mm_S8QstTJvicjuENwskatuuQK05KPuFw-KvRZeOH8iuEAMjRhkxEMPKJJnLcaT8zrPf9aqNs$
> 
> For the record, this got a bit mangled. I believe it should be:
> 
> Closes: https://lore.kernel.org/oe-lkp/202309201456.84c19e27-oliver.sang@intel.com/
> 
> Also, there is probably no need to resend because of this,
> but no blank line here, please.

Ok.

> 
>> Signed-off-by: Anjali Kulkarni <anjali.k.kulkarni@oracle.com>
>> ---
>> drivers/connector/cn_proc.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>> 
>> diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
>> index 05d562e9c8b1..01e17f18d187 100644
>> --- a/drivers/connector/cn_proc.c
>> +++ b/drivers/connector/cn_proc.c
>> @@ -104,13 +104,13 @@ static inline void send_msg(struct cn_msg *msg)
>> if (filter_data[0] == PROC_EVENT_EXIT) {
>> filter_data[1] =
>> ((struct proc_event *)msg->data)->event_data.exit.exit_code;
>> + cn_netlink_send_mult(msg, msg->len, 0, CN_IDX_PROC, GFP_NOWAIT,
>> +      cn_filter, (void *)filter_data);
>> } else {
>> - filter_data[1] = 0;
>> + cn_netlink_send_mult(msg, msg->len, 0, CN_IDX_PROC, GFP_NOWAIT,
>> +      NULL, NULL);
>> }
>> 
>> - cn_netlink_send_mult(msg, msg->len, 0, CN_IDX_PROC, GFP_NOWAIT,
>> -      cn_filter, (void *)filter_data);
>> -
> 
> I am wondering if you considered making cn_filter slightly smarter.
> It seems it already understands not to do very much for PROC_EVENT_ALL.

I could, but then we would be unnecessarily make an extra function call to cn_filter, and re-check this condition, which can be avoided if we do the check here. 

> 
>> local_unlock(&local_event.lock);
>> }
>> 
>> -- 
>> 2.42.0
Anjali Kulkarni Oct. 13, 2023, 11:01 p.m. UTC | #3
Please discard this patch, 

Anjali

> On Oct 13, 2023, at 5:01 AM, Simon Horman <horms@kernel.org> wrote:
> 
> On Tue, Oct 10, 2023 at 10:12:25PM -0700, Anjali Kulkarni wrote:
>> cn_netlink_send_mult() should be called with filter & filter_data only
>> for EXIT case. For all other events, filter & filter_data should be
>> NULL.
>> 
>> Fixes: 2aa1f7a1f47c ("connector/cn_proc: Add filtering to fix some bugs")
>> Reported-by: kernel test robot <oliver.sang@intel.com>
>> Closes: https://urldefense.com/v3/__https://lore.kernel.org/oe-lkp/202309201456.84c19e27-oliver.sang@intel.com__;!!ACWV5N9M2RV99hQ!PgqlHq_nOe_KlyKkB9Mm_S8QstTJvicjuENwskatuuQK05KPuFw-KvRZeOH8iuEAMjRhkxEMPKJJnLcaT8zrPf9aqNs$
> 
> For the record, this got a bit mangled. I believe it should be:
> 
> Closes: https://lore.kernel.org/oe-lkp/202309201456.84c19e27-oliver.sang@intel.com/
> 
> Also, there is probably no need to resend because of this,
> but no blank line here, please.
> 
>> Signed-off-by: Anjali Kulkarni <anjali.k.kulkarni@oracle.com>
>> ---
>> drivers/connector/cn_proc.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>> 
>> diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
>> index 05d562e9c8b1..01e17f18d187 100644
>> --- a/drivers/connector/cn_proc.c
>> +++ b/drivers/connector/cn_proc.c
>> @@ -104,13 +104,13 @@ static inline void send_msg(struct cn_msg *msg)
>> if (filter_data[0] == PROC_EVENT_EXIT) {
>> filter_data[1] =
>> ((struct proc_event *)msg->data)->event_data.exit.exit_code;
>> + cn_netlink_send_mult(msg, msg->len, 0, CN_IDX_PROC, GFP_NOWAIT,
>> +      cn_filter, (void *)filter_data);
>> } else {
>> - filter_data[1] = 0;
>> + cn_netlink_send_mult(msg, msg->len, 0, CN_IDX_PROC, GFP_NOWAIT,
>> +      NULL, NULL);
>> }
>> 
>> - cn_netlink_send_mult(msg, msg->len, 0, CN_IDX_PROC, GFP_NOWAIT,
>> -      cn_filter, (void *)filter_data);
>> -
> 
> I am wondering if you considered making cn_filter slightly smarter.
> It seems it already understands not to do very much for PROC_EVENT_ALL.
> 
>> local_unlock(&local_event.lock);
>> }
>> 
>> -- 
>> 2.42.0
diff mbox series

Patch

diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
index 05d562e9c8b1..01e17f18d187 100644
--- a/drivers/connector/cn_proc.c
+++ b/drivers/connector/cn_proc.c
@@ -104,13 +104,13 @@  static inline void send_msg(struct cn_msg *msg)
 	if (filter_data[0] == PROC_EVENT_EXIT) {
 		filter_data[1] =
 		((struct proc_event *)msg->data)->event_data.exit.exit_code;
+		cn_netlink_send_mult(msg, msg->len, 0, CN_IDX_PROC, GFP_NOWAIT,
+				     cn_filter, (void *)filter_data);
 	} else {
-		filter_data[1] = 0;
+		cn_netlink_send_mult(msg, msg->len, 0, CN_IDX_PROC, GFP_NOWAIT,
+				     NULL, NULL);
 	}
 
-	cn_netlink_send_mult(msg, msg->len, 0, CN_IDX_PROC, GFP_NOWAIT,
-			     cn_filter, (void *)filter_data);
-
 	local_unlock(&local_event.lock);
 }