* [PATCH] dm integrity: Use struct_group() to zero struct journal_sector
@ 2021-11-18 20:36 Kees Cook
2021-12-13 23:25 ` [dm-devel] " Gustavo A. R. Silva
0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2021-11-18 20:36 UTC (permalink / raw)
To: Alasdair Kergon
Cc: Kees Cook, Mike Snitzer, linux-kernel, dm-devel, linux-hardening
In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memset(), avoid intentionally writing across
neighboring fields.
Add struct_group() to mark region of struct journal_sector that should be
initialized to zero.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
drivers/md/dm-integrity.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
index 6319deccbe09..163c94ca4e5c 100644
--- a/drivers/md/dm-integrity.c
+++ b/drivers/md/dm-integrity.c
@@ -121,8 +121,10 @@ struct journal_entry {
#define JOURNAL_MAC_SIZE (JOURNAL_MAC_PER_SECTOR * JOURNAL_BLOCK_SECTORS)
struct journal_sector {
- __u8 entries[JOURNAL_SECTOR_DATA - JOURNAL_MAC_PER_SECTOR];
- __u8 mac[JOURNAL_MAC_PER_SECTOR];
+ struct_group(sectors,
+ __u8 entries[JOURNAL_SECTOR_DATA - JOURNAL_MAC_PER_SECTOR];
+ __u8 mac[JOURNAL_MAC_PER_SECTOR];
+ );
commit_id_t commit_id;
};
@@ -2870,7 +2872,8 @@ static void init_journal(struct dm_integrity_c *ic, unsigned start_section,
wraparound_section(ic, &i);
for (j = 0; j < ic->journal_section_sectors; j++) {
struct journal_sector *js = access_journal(ic, i, j);
- memset(&js->entries, 0, JOURNAL_SECTOR_DATA);
+ BUILD_BUG_ON(sizeof(js->sectors) != JOURNAL_SECTOR_DATA);
+ memset(&js->sectors, 0, sizeof(js->sectors));
js->commit_id = dm_integrity_commit_id(ic, i, j, commit_seq);
}
for (j = 0; j < ic->journal_section_entries; j++) {
--
2.30.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [dm-devel] [PATCH] dm integrity: Use struct_group() to zero struct journal_sector
2021-11-18 20:36 [PATCH] dm integrity: Use struct_group() to zero struct journal_sector Kees Cook
@ 2021-12-13 23:25 ` Gustavo A. R. Silva
0 siblings, 0 replies; 2+ messages in thread
From: Gustavo A. R. Silva @ 2021-12-13 23:25 UTC (permalink / raw)
To: Kees Cook
Cc: Alasdair Kergon, dm-devel, linux-hardening, Mike Snitzer, linux-kernel
On Thu, Nov 18, 2021 at 12:36:40PM -0800, Kees Cook wrote:
> In preparation for FORTIFY_SOURCE performing compile-time and run-time
> field bounds checking for memset(), avoid intentionally writing across
> neighboring fields.
>
> Add struct_group() to mark region of struct journal_sector that should be
> initialized to zero.
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> ---
> drivers/md/dm-integrity.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
> index 6319deccbe09..163c94ca4e5c 100644
> --- a/drivers/md/dm-integrity.c
> +++ b/drivers/md/dm-integrity.c
> @@ -121,8 +121,10 @@ struct journal_entry {
> #define JOURNAL_MAC_SIZE (JOURNAL_MAC_PER_SECTOR * JOURNAL_BLOCK_SECTORS)
>
> struct journal_sector {
> - __u8 entries[JOURNAL_SECTOR_DATA - JOURNAL_MAC_PER_SECTOR];
> - __u8 mac[JOURNAL_MAC_PER_SECTOR];
> + struct_group(sectors,
> + __u8 entries[JOURNAL_SECTOR_DATA - JOURNAL_MAC_PER_SECTOR];
> + __u8 mac[JOURNAL_MAC_PER_SECTOR];
> + );
> commit_id_t commit_id;
> };
>
> @@ -2870,7 +2872,8 @@ static void init_journal(struct dm_integrity_c *ic, unsigned start_section,
> wraparound_section(ic, &i);
> for (j = 0; j < ic->journal_section_sectors; j++) {
> struct journal_sector *js = access_journal(ic, i, j);
> - memset(&js->entries, 0, JOURNAL_SECTOR_DATA);
> + BUILD_BUG_ON(sizeof(js->sectors) != JOURNAL_SECTOR_DATA);
> + memset(&js->sectors, 0, sizeof(js->sectors));
> js->commit_id = dm_integrity_commit_id(ic, i, j, commit_seq);
> }
> for (j = 0; j < ic->journal_section_entries; j++) {
> --
> 2.30.2
>
> --
> dm-devel mailing list
> dm-devel@redhat.com
> https://listman.redhat.com/mailman/listinfo/dm-devel
>
>
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-13 23:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-18 20:36 [PATCH] dm integrity: Use struct_group() to zero struct journal_sector Kees Cook
2021-12-13 23:25 ` [dm-devel] " Gustavo A. R. Silva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).