linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] x86/mm/pgtable: Fix Wstringop-overflow warnings
@ 2022-04-01  0:58 Gustavo A. R. Silva
  2022-04-01 13:12 ` Peter Zijlstra
  0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2022-04-01  0:58 UTC (permalink / raw)
  To: Dave Hansen, Andy Lutomirski, Peter Zijlstra, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, H. Peter Anvin
  Cc: x86, linux-kernel, Gustavo A. R. Silva, linux-hardening

Fix the following -Wstringop-overflow warnings when building with GCC-11:

.arch/x86/mm/pgtable.c: In function ‘pgd_alloc’:
arch/x86/mm/pgtable.c:437:13: warning: ‘preallocate_pmds.constprop’ accessing 8 bytes in a region of size 0 [-Wstringop-overflow=]
  437 |         if (preallocate_pmds(mm, pmds, PREALLOCATED_PMDS) != 0)
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/mm/pgtable.c:437:13: note: referencing argument 2 of type ‘pmd_t **’
arch/x86/mm/pgtable.c:225:12: note: in a call to function ‘preallocate_pmds.constprop’
  225 | static int preallocate_pmds(struct mm_struct *mm, pmd_t *pmds[], int count)
      |            ^~~~~~~~~~~~~~~~
arch/x86/mm/pgtable.c:440:13: warning: ‘preallocate_pmds.constprop’ accessing 8 bytes in a region of size 0 [-Wstringop-overflow=]
  440 |         if (preallocate_pmds(mm, u_pmds, PREALLOCATED_USER_PMDS) != 0)
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/mm/pgtable.c:440:13: note: referencing argument 2 of type ‘pmd_t **’
arch/x86/mm/pgtable.c:225:12: note: in a call to function ‘preallocate_pmds.constprop’
  225 | static int preallocate_pmds(struct mm_struct *mm, pmd_t *pmds[], int count)
      |            ^~~~~~~~~~~~~~~~
arch/x86/mm/pgtable.c:462:9: warning: ‘free_pmds.constprop’ accessing 8 bytes in a region of size 0 [-Wstringop-overflow=]
  462 |         free_pmds(mm, u_pmds, PREALLOCATED_USER_PMDS);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/mm/pgtable.c:462:9: note: referencing argument 2 of type ‘pmd_t **’
arch/x86/mm/pgtable.c:213:13: note: in a call to function ‘free_pmds.constprop’
  213 | static void free_pmds(struct mm_struct *mm, pmd_t *pmds[], int count)
      |             ^~~~~~~~~
arch/x86/mm/pgtable.c:455:9: warning: ‘pgd_prepopulate_user_pmd’ accessing 8 bytes in a region of size 0 [-Wstringop-overflow=]
  455 |         pgd_prepopulate_user_pmd(mm, pgd, u_pmds);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/mm/pgtable.c:455:9: note: referencing argument 3 of type ‘pmd_t **’
arch/x86/mm/pgtable.c:320:13: note: in a call to function ‘pgd_prepopulate_user_pmd’
  320 | static void pgd_prepopulate_user_pmd(struct mm_struct *mm,
      |             ^~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/mm/pgtable.c:464:9: warning: ‘free_pmds.constprop’ accessing 8 bytes in a region of size 0 [-Wstringop-overflow=]
  464 |         free_pmds(mm, pmds, PREALLOCATED_PMDS);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/mm/pgtable.c:464:9: note: referencing argument 2 of type ‘pmd_t **’
arch/x86/mm/pgtable.c:213:13: note: in a call to function ‘free_pmds.constprop’
  213 | static void free_pmds(struct mm_struct *mm, pmd_t *pmds[], int count)
      |             ^~~~~~~~~

by using pointer notation instead of array notation as a workaround for
the above GCC warnings.

This helps with the ongoing efforts to globally enable
-Wstringop-overflow.

Link: https://github.com/KSPP/linux/issues/181
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 arch/x86/mm/pgtable.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index 3481b35cb4ec..aecaebf3c3d0 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -210,7 +210,7 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
 #define MAX_PREALLOCATED_USER_PMDS 0
 #endif	/* CONFIG_X86_PAE */
 
-static void free_pmds(struct mm_struct *mm, pmd_t *pmds[], int count)
+static void free_pmds(struct mm_struct *mm, pmd_t **pmds, int count)
 {
 	int i;
 
@@ -222,7 +222,7 @@ static void free_pmds(struct mm_struct *mm, pmd_t *pmds[], int count)
 		}
 }
 
-static int preallocate_pmds(struct mm_struct *mm, pmd_t *pmds[], int count)
+static int preallocate_pmds(struct mm_struct *mm, pmd_t **pmds, int count)
 {
 	int i;
 	bool failed = false;
@@ -318,7 +318,7 @@ static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
 
 #ifdef CONFIG_PAGE_TABLE_ISOLATION
 static void pgd_prepopulate_user_pmd(struct mm_struct *mm,
-				     pgd_t *k_pgd, pmd_t *pmds[])
+				     pgd_t *k_pgd, pmd_t **pmds)
 {
 	pgd_t *s_pgd = kernel_to_user_pgdp(swapper_pg_dir);
 	pgd_t *u_pgd = kernel_to_user_pgdp(k_pgd);
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH][next] x86/mm/pgtable: Fix Wstringop-overflow warnings
  2022-04-01  0:58 [PATCH][next] x86/mm/pgtable: Fix Wstringop-overflow warnings Gustavo A. R. Silva
@ 2022-04-01 13:12 ` Peter Zijlstra
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2022-04-01 13:12 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Dave Hansen, Andy Lutomirski, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, H. Peter Anvin, x86, linux-kernel,
	linux-hardening

On Thu, Mar 31, 2022 at 07:58:34PM -0500, Gustavo A. R. Silva wrote:
> Fix the following -Wstringop-overflow warnings when building with GCC-11:
> 
> .arch/x86/mm/pgtable.c: In function ‘pgd_alloc’:
> arch/x86/mm/pgtable.c:437:13: warning: ‘preallocate_pmds.constprop’ accessing 8 bytes in a region of size 0 [-Wstringop-overflow=]
>   437 |         if (preallocate_pmds(mm, pmds, PREALLOCATED_PMDS) != 0)
>       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> arch/x86/mm/pgtable.c:437:13: note: referencing argument 2 of type ‘pmd_t **’
> arch/x86/mm/pgtable.c:225:12: note: in a call to function ‘preallocate_pmds.constprop’
>   225 | static int preallocate_pmds(struct mm_struct *mm, pmd_t *pmds[], int count)
>       |            ^~~~~~~~~~~~~~~~
> arch/x86/mm/pgtable.c:440:13: warning: ‘preallocate_pmds.constprop’ accessing 8 bytes in a region of size 0 [-Wstringop-overflow=]
>   440 |         if (preallocate_pmds(mm, u_pmds, PREALLOCATED_USER_PMDS) != 0)
>       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> arch/x86/mm/pgtable.c:440:13: note: referencing argument 2 of type ‘pmd_t **’
> arch/x86/mm/pgtable.c:225:12: note: in a call to function ‘preallocate_pmds.constprop’
>   225 | static int preallocate_pmds(struct mm_struct *mm, pmd_t *pmds[], int count)
>       |            ^~~~~~~~~~~~~~~~
> arch/x86/mm/pgtable.c:462:9: warning: ‘free_pmds.constprop’ accessing 8 bytes in a region of size 0 [-Wstringop-overflow=]
>   462 |         free_pmds(mm, u_pmds, PREALLOCATED_USER_PMDS);
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> arch/x86/mm/pgtable.c:462:9: note: referencing argument 2 of type ‘pmd_t **’
> arch/x86/mm/pgtable.c:213:13: note: in a call to function ‘free_pmds.constprop’
>   213 | static void free_pmds(struct mm_struct *mm, pmd_t *pmds[], int count)
>       |             ^~~~~~~~~
> arch/x86/mm/pgtable.c:455:9: warning: ‘pgd_prepopulate_user_pmd’ accessing 8 bytes in a region of size 0 [-Wstringop-overflow=]
>   455 |         pgd_prepopulate_user_pmd(mm, pgd, u_pmds);
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> arch/x86/mm/pgtable.c:455:9: note: referencing argument 3 of type ‘pmd_t **’
> arch/x86/mm/pgtable.c:320:13: note: in a call to function ‘pgd_prepopulate_user_pmd’
>   320 | static void pgd_prepopulate_user_pmd(struct mm_struct *mm,
>       |             ^~~~~~~~~~~~~~~~~~~~~~~~
> arch/x86/mm/pgtable.c:464:9: warning: ‘free_pmds.constprop’ accessing 8 bytes in a region of size 0 [-Wstringop-overflow=]
>   464 |         free_pmds(mm, pmds, PREALLOCATED_PMDS);
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> arch/x86/mm/pgtable.c:464:9: note: referencing argument 2 of type ‘pmd_t **’
> arch/x86/mm/pgtable.c:213:13: note: in a call to function ‘free_pmds.constprop’
>   213 | static void free_pmds(struct mm_struct *mm, pmd_t *pmds[], int count)
>       |             ^~~~~~~~~
> 
> by using pointer notation instead of array notation as a workaround for
> the above GCC warnings.

'Workaround' implies the warning is on crack...

> This helps with the ongoing efforts to globally enable
> -Wstringop-overflow.

which puts to question this endeavour, why are you wanting to have this
if its crap?


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-01 13:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01  0:58 [PATCH][next] x86/mm/pgtable: Fix Wstringop-overflow warnings Gustavo A. R. Silva
2022-04-01 13:12 ` Peter Zijlstra

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).