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]
Date: Fri, 22 Mar 2024 04:33:27 +0000
From: Michael Kelley <mhklinux@...look.com>
To: Petr Tesarik <petrtesarik@...weicloud.com>, Christoph Hellwig
	<hch@....de>, Marek Szyprowski <m.szyprowski@...sung.com>, Robin Murphy
	<robin.murphy@....com>, Petr Tesarik <petr.tesarik1@...wei-partners.com>,
	Will Deacon <will@...nel.org>, open list <linux-kernel@...r.kernel.org>,
	"open list:DMA MAPPING HELPERS" <iommu@...ts.linux.dev>
CC: Roberto Sassu <roberto.sassu@...weicloud.com>, Petr Tesarik
	<petr@...arici.cz>
Subject: RE: [PATCH v3 2/2] bug: introduce ASSERT_VAR_CAN_HOLD()

From: Petr Tesarik <petrtesarik@...weicloud.com> Sent: Thursday, March 21, 2024 10:19 AM
> 
> Introduce an ASSERT_VAR_CAN_HOLD() macro to check at build time that a
> variable can hold the given value.
> 
> Use this macro in swiotlb to make sure that the list and pad_slots fields
> of struct io_tlb_slot are big enough to hold the maximum possible value of
> IO_TLB_SEGSIZE.
> 
> Signed-off-by: Petr Tesarik <petr.tesarik1@...wei-partners.com>
> ---
>  include/linux/build_bug.h | 10 ++++++++++
>  kernel/dma/swiotlb.c      |  2 ++
>  2 files changed, 12 insertions(+)
> 
> diff --git a/include/linux/build_bug.h b/include/linux/build_bug.h
> index 3aa3640f8c18..6e2486508af0 100644
> --- a/include/linux/build_bug.h
> +++ b/include/linux/build_bug.h
> @@ -86,4 +86,14 @@
>  		"Offset of " #field " in " #type " has changed.")
> 
> 
> +/*
> + * Compile time check that a variable can hold the given value
> + */
> +#define ASSERT_VAR_CAN_HOLD(var, value) ({		\
> +	typeof(value) __val = (value);			\
> +	typeof(var) __tmp = __val;			\
> +	BUILD_BUG_ON_MSG(__tmp != __val,		\
> +		#var " cannot hold " #value ".");	\
> +})
> +
>  #endif	/* _LINUX_BUILD_BUG_H */
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 3779a48eec9b..8256fcdc0cf6 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -285,6 +285,8 @@ static void swiotlb_init_io_tlb_pool(struct io_tlb_pool *mem, phys_addr_t start,
>  		mem->areas[i].used = 0;
>  	}
> 
> +	ASSERT_VAR_CAN_HOLD(mem->slots[0].list, IO_TLB_SEGSIZE);
> +	ASSERT_VAR_CAN_HOLD(mem->slots[0].pad_slots, IO_TLB_SEGSIZE);
>  	for (i = 0; i < mem->nslabs; i++) {
>  		mem->slots[i].list = min(IO_TLB_SEGSIZE - io_tlb_offset(i),
>  					 mem->nslabs - i);
> --
> 2.34.1

This was tested implicitly as part of my broader testing of
Patch 1 of the series.  From a code review standpoint, I
don't feel very competent to recognize potential problems
in ASSERT_VAR_CAN_HOLD(), so I haven't given a
"Reviewed-by:" for this patch.

Tested-by: Michael Kelley <mhklinux@...look.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ