Re: [PATCH i-g-t v4 5/5] lib/gem_engine_topology: Fix broken compare of device links

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Janusz,
On 2024-07-18 at 10:55:16 +0200, Janusz Krzysztofik wrote:
> When looking for a primary counterpart of a render device, we compare
> "device" links of both nodes.  If those links point to the same device
> then we know we've found the correct primary node.
> 
> However, readlinkat() function we use doesn't explicitly terminate read in
> strings with null characters, and then the comparison occasionally fails.
> 
> Process the second (potential primary counterpart) node only if its
> "device" link is of the same length as that of the render node, and limit
> the number of compared characters to that length.
> 
> Closes: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/6268
> Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@xxxxxxxxxxxxxxx>

Reviewed-by: Kamil Konieczny <kamil.konieczny@xxxxxxxxxxxxxxx>

> ---
>  lib/i915/gem_engine_topology.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/i915/gem_engine_topology.c b/lib/i915/gem_engine_topology.c
> index c8c1079223..c251060341 100644
> --- a/lib/i915/gem_engine_topology.c
> +++ b/lib/i915/gem_engine_topology.c
> @@ -467,7 +467,8 @@ static int __open_primary(int dir)
>  	if (minor < 64)
>  		return dir;
>  
> -	if (igt_debug_on(readlinkat(dir, "device", target, sizeof(target)) < 0))
> +	len = readlinkat(dir, "device", target, sizeof(target));
> +	if (igt_debug_on(len <= 0))
>  		return dir;
>  
>  	close(dir);
> @@ -477,8 +478,8 @@ static int __open_primary(int dir)
>  		if (dir < 0)
>  			continue;
>  
> -		if (readlinkat(dir, "device", device, sizeof(device)) > 0 &&
> -		    !strcmp(device, target))
> +		if (readlinkat(dir, "device", device, sizeof(device)) == len &&
> +		    !strncmp(device, target, len))
>  			break;
>  
>  		close(dir);
> -- 
> 2.45.2
> 



[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux