lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YpZCWbfNE32EzCnz@arm.com>
Date:   Tue, 31 May 2022 17:29:13 +0100
From:   Catalin Marinas <catalin.marinas@....com>
To:     Patrick Wang <patrick.wang.shcn@...il.com>
Cc:     akpm@...ux-foundation.org, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org, yee.lee@...iatek.com
Subject: Re: [PATCH] mm: kmemleak: check boundary of objects allocated with
 physical address when scan

On Tue, May 31, 2022 at 11:08:23PM +0800, Patrick Wang wrote:
> @@ -1132,8 +1135,13 @@ EXPORT_SYMBOL(kmemleak_no_scan);
>  void __ref kmemleak_alloc_phys(phys_addr_t phys, size_t size, int min_count,
>  			       gfp_t gfp)
>  {
> -	if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn)
> -		kmemleak_alloc(__va(phys), size, min_count, gfp);
> +	pr_debug("%s(0x%p, %zu, %d)\n", __func__, __va(phys), size, min_count);

I'd print just phys here since that's the function argument.

> +	if (kmemleak_enabled && (unsigned long)__va(phys) >= PAGE_OFFSET &&
> +	    !IS_ERR(__va(phys)))
> +		/* create object with OBJECT_PHYS flag */
> +		create_object((unsigned long)__va(phys), size, min_count,
> +			      gfp, true);

Do we still need to check for __va(phys) >= PAGE_OFFSET? Also I don't
think IS_ERR(__va(phys)) makes sense, we can't store an error in a
physical address. The kmemleak_alloc_phys() function is only called on
successful allocation, so shouldn't bother with error codes.

> @@ -1436,6 +1441,13 @@ static void kmemleak_scan(void)
>  			dump_object_info(object);
>  		}
>  #endif
> +
> +		/* outside lowmem, make it black */

Maybe a bit more verbose:

		/* ignore objects outside lowmem (paint them black) */

> +		if (object->flags & OBJECT_PHYS)
> +			if (PHYS_PFN(__pa((void *)object->pointer)) < min_low_pfn ||
> +			    PHYS_PFN(__pa((void *)object->pointer)) >= max_low_pfn)
> +				__paint_it(object, KMEMLEAK_BLACK);

I'd skip the checks if the object is OBJECT_NO_SCAN (side-effect of
__paint_it()) so that the next scan won't have to go through the __pa()
checks again. It's also probably more correct to check the upper object
boundary). Something like:

		if ((object->flags & OBJECT_PHYS) &&
		    !(object->flags & OBJECT_NO_SCAN)) {
			unsigned long phys = __pa((void *)object->pointer);
			if (PHYS_PFN(phys) < min_low_pfn ||
			    PHYS_PFN(phys + object->size) >= max_low_pfn)
				__paint_it(object, KMEMLEAK_BLACK);
		}

Thanks.

-- 
Catalin

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ