xen/gnttab: fix gnttab_acquire_resource()
PATCH 1/1 xen/gnttab: fix gnttab_acquire_resource()
Commit 9dc46386d89d ("gnttab: work around "may be used uninitialized" warning") was wrong, as vaddr can legitimately be NULL in case XENMEM_resource_grant_table_id_status was specified for a grant table v1. This would result in crashes in debug builds due to ASSERT_UNREACHABLE() triggering.
Basically revert said commit, but keep returning -ENODATA in that case.
---
Might be considered for 4.17 and for backporting
--- xen/common/grant_table.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
xen/common/grant_table.c +3 -11
@@ -4125,7 +4125,10 @@ int gnttab_acquire_resource(case XENMEM_resource_grant_table_id_status:if ( gt->gt_version !=2 ) + { + rc = -ENODATA ;break ; + }/* Check that void ** is a suitable representation for gt->status. */ BUILD_BUG_ON(!__builtin_types_compatible_p(
@@ -4135,17 +4138,6 @@ int gnttab_acquire_resource(break ; } -/* -* Some older toolchains can't spot that vaddrs won't remain uninitialized -* on non-error paths, and hence it needs setting to NULL at the top of the -* function. Leave some runtime safety. -*/ -if ( !vaddrs ) - { -ASSERT_UNREACHABLE (); - rc = -ENODATA ; - } -/* Any errors? Bad id, or from growing the table? */ if ( rc ) goto out;
Signature · 1 line
2.35.3
Hi Juergen,
Quoted 10 lines
-----Original Message-----
From: Juergen Gross <[email protected]>
Subject: [PATCH] xen/gnttab: fixgnttab_acquire_resource()Commit
9dc46386d89d("gnttab: work around "may be used uninitialized" warning") was wrong, as vaddr can legitimately be NULL in caseXENMEM_resource_grant_table_id_statuswas specified for a grant table v1. This would result in crashes in debug builds due toASSERT_UNREACHABLE()triggering.
Quoted 7 lines
Basically revert said commit, but keep returning
-ENODATAin that case.Fixes 9dc46386d89d ("gnttab: work around "may be used uninitialized"warning")
Signed-off-by Juergen Gross <[email protected]>---
Might be considered for 4.17 and for backporting
Of course, feel free to add:
If the maintainer give an ack about this patch.
Kind regards,
Henry
Hi Henry,
Quoted 18 lines · Henry Wang
Quoted 10 lines
-----Original Message-----
From: Juergen Gross <[email protected]>
Subject: [PATCH] xen/gnttab: fixgnttab_acquire_resource()Commit
9dc46386d89d("gnttab: work around "may be used uninitialized" warning") was wrong, as vaddr can legitimately be NULL in caseXENMEM_resource_grant_table_id_statuswas specified for a grant table v1. This would result in crashes in debug builds due toASSERT_UNREACHABLE()triggering.Quoted 7 lines
Basically revert said commit, but keep returning
-ENODATAin that case.Fixes 9dc46386d89d ("gnttab: work around "may be used uninitialized"warning")
Signed-off-by Juergen Gross <[email protected]>---
Might be considered for 4.17 and for backporting
Quoted 3 lines
Of course, feel free to add:
Release-acked-by Henry Wang <[email protected]>
Unrelated to this patch, but as this is your first Released-acked-by tag, I wanted to check the policy going forward.
From now, will any new patch need your approval before been merged?
Cheers,
Signature · 1 line
Julien Grall
Quoted 4 lines · Julien Grall
Unrelated to this patch, but as this is your first Released-acked-by tag, I wanted to check the policy going forward.
From now, will any new patch need your approval before been merged?
It was my understanding (from past releases) that bug fixes would be fine to go in without until code freeze (in 3 weeks as per the current schedule).
Jan
Hi Jan,
Quoted 9 lines · Jan Beulich
Quoted 4 lines · Julien Grall
Unrelated to this patch, but as this is your first Released-acked-by tag, I wanted to check the policy going forward.
From now, will any new patch need your approval before been merged?
It was my understanding (from past releases) that bug fixes would be fine to go in without until code freeze (in 3 weeks as per the current schedule).
This is my understanding as well. But I wanted to check with Henry just in case he decided something different.
Cheers,
Signature · 1 line
Julien Grall
Hi Julien,
Quoted 25 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Subject: Re: [PATCH] xen/gnttab: fixgnttab_acquire_resource()Hi Henry,
Quoted 18 lines · Henry Wang
Quoted 17 lines
-----Original Message-----
From: Juergen Gross <[email protected]>
Subject: [PATCH] xen/gnttab: fixgnttab_acquire_resource()Commit
9dc46386d89d("gnttab: work around "may be used uninitialized" warning") was wrong, as vaddr can legitimately be NULL in caseXENMEM_resource_grant_table_id_statuswas specified for a grant table v1. This would result in crashes in debug builds due toASSERT_UNREACHABLE()triggering.Basically revert said commit, but keep returning
-ENODATAin that case.Fixes 9dc46386d89d ("gnttab: work around "may be used uninitialized"warning")
Signed-off-by Juergen Gross <[email protected]>---
Might be considered for 4.17 and for backporting
Quoted 8 lines
Quoted 3 lines
Of course, feel free to add:
Release-acked-by Henry Wang <[email protected]>Unrelated to this patch, but as this is your first Released-acked-by tag, I wanted to check the policy going forward.
From now, will any new patch need your approval before been merged?
I would say from now is a little bit too early. I think maintainers can still commit patches (fixes and not new feature related) until the code freeze (end of this month).
I am providing this tag just to show I am happy to add this to 4.17 since Juergen mentioned this in scissors line comment.
Kind regards,
Henry
Quoted 5 lines
Cheers,
--
Julien Grall
Hi Juergen,
Quoted 7 lines · Juergen Gross
Commit
9dc46386d89d("gnttab: work around "may be used uninitialized" warning") was wrong, as vaddr can legitimately be NULL in caseXENMEM_resource_grant_table_id_statuswas specified for a grant table v1. This would result in crashes in debug builds due toASSERT_UNREACHABLE()triggering.Basically revert said commit, but keep returning
-ENODATAin that case.
This commit was introduced to silence a compiler warning (treated as error in Xen build system). As you revert it, did you check the said compiler (IIRC GCC 4.3) was still happy?
Quoted 31 lines
Fixes 9dc46386d89d ("gnttab: work around "may be used uninitialized" warning")Signed-off-by Juergen Gross <[email protected]>---
Might be considered for 4.17 and for backporting--- xen/common/grant_table.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)xen/common/grant_table.c +3
-4@@ -4125,7 +4125,10 @@ int gnttab_acquire_resource(case XENMEM_resource_grant_table_id_status:if ( gt->gt_version !=2 ) + { + rc = -ENODATA ;break ; + }/* Check that void ** is a suitable representation for gt->status. */ BUILD_BUG_ON(!__builtin_types_compatible_p(@@ -4135,17 +4138,6 @@ int gnttab_acquire_resource(break ; } -/* -* Some older toolchains can't spot that vaddrs won't remain uninitialized -* on non-error paths, and hence it needs setting to NULL at the top of the -* function. Leave some runtime safety.
xen/common/grant_table.c int gnttab_acquire_resource( · line 4143
Quoted 10 lines
xen/common/grant_table.c +0
-7-*/ -if ( !vaddrs ) - { -ASSERT_UNREACHABLE (); - rc = -ENODATA ; - } -/* Any errors? Bad id, or from growing the table? */ if ( rc ) goto out;
Looking at the code just below the loop is:
for ( i = 0; i < nr_frames; ++i )
mfn_list[i] = virt_to_mfn(vaddrs[frame + 1]);
Given that 'nr_frames' is provided by the caller it is a bit unclear how we guarantee that 'vaddrs' will not be NULL when nr_frames > 0.
Can you explain how you came to the conclusion that this is not possible?
Cheers,
Signature · 1 line
Julien Grall
Quoted 9 lines · Julien Grall
Hi Juergen,
Quoted 6 lines · Juergen Gross
Commit
9dc46386d89d("gnttab: work around "may be used uninitialized" warning") was wrong, as vaddr can legitimately be NULL in caseXENMEM_resource_grant_table_id_statuswas specified for a grant table v1. This would result in crashes in debug builds due toASSERT_UNREACHABLE()triggering.
Quoted 3 lines
Quoted 1 line
Basically revert said commit, but keep returning
-ENODATAin that case.This commit was introduced to silence a compiler warning (treated as error in Xen build system). As you revert it, did you check the said compiler (IIRC GCC 4.3) was still happy?
I didn't remove the vaddr initializer.
Quoted 42 lines
Quoted 29 lines
Fixes 9dc46386d89d ("gnttab: work around "may be used uninitialized" warning")Signed-off-by Juergen Gross <[email protected]>---
Might be considered for 4.17 and for backporting
---
xen/common/grant_table.c| 14 +++-----------1 file changed, 3 insertions(+), 11 deletions(-)xen/common/grant_table.c +0
-0@@ -4125,7 +4125,10 @@ int gnttab_acquire_resource(case
XENMEM_resource_grant_table_id_status:
if (gt->gt_version!= 2 )
+ {
+ rc =-ENODATA;
break;
+ }
/* Check that void ** is a suitable representation forgt->status. */ BUILD_BUG_ON(!__builtin_types_compatible_p(xen/common/grant_table.c +0
-4@@ -4135,17 +4138,6 @@ int gnttab_acquire_resource( break; } - /* -* Some older toolchains can't spot that vaddrs won't remain uninitialized -* on non-error paths, and hence it needs setting to NULL at the top of the -* function. Leave some runtime safety. xen/common/grant_table.c int gnttab_acquire_resource( · line 4142
Quoted 10 lines
xen/common/grant_table.c +0
-7-*/ - if ( !vaddrs ) - { - ASSERT_UNREACHABLE(); - rc = -ENODATA; - } - /* Any errors? Bad id, or from growing the table? */ if ( rc ) goto out;Looking at the code just below the loop is:
Quoted 6 lines
for ( i = 0; i <
nr_frames; ++i )
mfn_list[i] =virt_to_mfn(vaddrs[frame + 1]);Given that '
nr_frames' is provided by the caller it is a bit unclear how we guarantee that 'vaddrs' will not be NULL whennr_frames> 0.Can you explain how you came to the conclusion that this is not possible?
We can reach this point only in case rc is 0.
rc can be 0 only in case gnttab_get_shared_frame_mfn() or gnttab_get_status_frame_mfn() returned 0, which will be the case only, if the value vaddrs was set to before calling those functions was valid.
Juergen
Hi Jan,
Quoted 10 lines · Juergen Gross
Quoted 9 lines · Julien Grall
Hi Juergen,
Quoted 6 lines · Juergen Gross
Commit
9dc46386d89d("gnttab: work around "may be used uninitialized" warning") was wrong, as vaddr can legitimately be NULL in caseXENMEM_resource_grant_table_id_statuswas specified for a grant table v1. This would result in crashes in debug builds due toASSERT_UNREACHABLE()triggering.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Basically revert said commit, but keep returning
-ENODATAin that case.This commit was introduced to silence a compiler warning (treated as error in Xen build system). As you revert it, did you check the said compiler (IIRC GCC 4.3) was still happy?
I didn't remove the vaddr initializer.
Ok so it is not a full revert as you implied above. I think it would be good to write "partially".
Quoted 50 lines
Quoted 50 lines
Quoted 34 lines
Fixes 9dc46386d89d ("gnttab: work around "may be used uninitialized" warning")Signed-off-by Juergen Gross <[email protected]>---
Might be considered for 4.17 and for backporting
---
xen/common/grant_table.c| 14 +++-----------1 file changed, 3 insertions(+), 11 deletions(-)xen/common/grant_table.c +0
-0@@ -4125,7 +4125,10 @@ int gnttab_acquire_resource(case
XENMEM_resource_grant_table_id_status:
if (gt->gt_version!= 2 )
+ {
+ rc =-ENODATA;
break;
+ }
/* Check that void ** is a suitable representation forgt->status. */ BUILD_BUG_ON(!__builtin_types_compatible_p(xen/common/grant_table.c +0
-2@@ -4135,17 +4138,6 @@ int gnttab_acquire_resource( break; } - /* -* Some older toolchains can't spot that vaddrs won't remain uninitialized
- * on non-error paths, and hence it needs setting to NULL at the top of the
- * function. Leave some runtime safety.
- */
- if ( !vaddrs )Quoted 8 lines
- {
-ASSERT_UNREACHABLE();
- rc =-ENODATA;
- }
-
/* Any errors? Bad id, or from growing the table? */ if ( rc )
goto out;Looking at the code just below the loop is:
for ( i = 0; i <
nr_frames; ++i )
mfn_list[i] =virt_to_mfn(vaddrs[frame + 1]);Given that '
nr_frames' is provided by the caller it is a bit unclear how we guarantee that 'vaddrs' will not be NULL whennr_frames> 0.
Quoted 7 lines
Quoted 1 line
Can you explain how you came to the conclusion that this is not possible?
We can reach this point only in case rc is 0.
rc can be 0 only in case
gnttab_get_shared_frame_mfn()orgnttab_get_status_frame_mfn()returned 0, which will be the case only, if the value vaddrs was set to before calling those functions was valid.
This is somewhat fragile. As we had to silence the compiler, the check was added to avoid any addition of code that may not properly set 'vaddrs' (The compiler can't help us anymore).
So I think I would prefer what Jan suggested. We should check 'rc' *and* then 'vaddrs'.
Cheers,
Signature · 1 line
Julien Grall
Quoted 21 lines · Juergen Gross
Commit
9dc46386d89d("gnttab: work around "may be used uninitialized" warning") was wrong, as vaddr can legitimately be NULL in caseXENMEM_resource_grant_table_id_statuswas specified for a grant table v1. This would result in crashes in debug builds due toASSERT_UNREACHABLE()triggering.Basically revert said commit, but keep returning
-ENODATAin that case.Fixes 9dc46386d89d ("gnttab: work around "may be used uninitialized" warning")Signed-off-by Juergen Gross <[email protected]>---
Might be considered for 4.17 and for backporting--- xen/common/grant_table.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)xen/common/grant_table.c +0
-0
xen/common/grant_table.c int gnttab_acquire_resource( · line 4131
Quoted 7 lines
xen/common/grant_table.c +3
-0@@ -4125,7 +4125,10 @@ int gnttab_acquire_resource(case XENMEM_resource_grant_table_id_status:if ( gt->gt_version !=2 ) + { + rc = -ENODATA ;break ; + }
This path is supposed to produce -EINVAL.
xen/common/grant_table.c int gnttab_acquire_resource( · line 4143
Quoted 10 lines
xen/common/grant_table.c +0
-6@@ -4135,17 +4138,6 @@ int gnttab_acquire_resource(break ; } -/* -* Some older toolchains can't spot that vaddrs won't remain uninitialized -* on non-error paths, and hence it needs setting to NULL at the top of the -* function. Leave some runtime safety. -*/ -if ( !vaddrs )
I guess this wants amending by "&& !rc"?
Jan
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Juergen Gross
Commit
9dc46386d89d("gnttab: work around "may be used uninitialized" warning") was wrong, as vaddr can legitimately be NULL in caseXENMEM_resource_grant_table_id_statuswas specified for a grant table v1. This would result in crashes in debug builds due toASSERT_UNREACHABLE()triggering.Basically revert said commit, but keep returning
-ENODATAin that case.Fixes 9dc46386d89d ("gnttab: work around "may be used uninitialized" warning")Signed-off-by Juergen Gross <[email protected]>---
Might be considered for 4.17 and for backporting--- xen/common/grant_table.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)xen/common/grant_table.c +0
-0@@ -4125,7 +4125,10 @@ int gnttab_acquire_resource(
Quoted 8 lines
xen/common/grant_table.c int gnttab_acquire_resource( · line 4131
Quoted 6 lines
xen/common/grant_table.c +3
-0case XENMEM_resource_grant_table_id_status:if ( gt->gt_version !=2 ) + { + rc = -ENODATA ;break ; + }This path is supposed to produce
-EINVAL.
Okay.
Quoted 5 lines
Quoted 5 lines
xen/common/grant_table.c +0
-0@@ -4135,17 +4138,6 @@ int gnttab_acquire_resource(break ; }
Quoted 8 lines
xen/common/grant_table.c int gnttab_acquire_resource( · line 4143
Quoted 6 lines
xen/common/grant_table.c +0
-6-/* -* Some older toolchains can't spot that vaddrs won't remain uninitialized -* on non-error paths, and hence it needs setting to NULL at the top of the -* function. Leave some runtime safety. -*/ -if ( !vaddrs )I guess this wants amending by "&& !rc"?
I can do that, if you like that better.
Juergen
Kind regards,
Henry
Quoted 66 lines
-----Original Message-----
From: Juergen Gross <[email protected]>
Sent: Friday, September 9, 2022 5:26 PM
To: Jan Beulich <[email protected]>
Cc: Henry Wang <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; [email protected]
Subject: Re: [PATCH] xen/gnttab: fixgnttab_acquire_resource()Quoted 10 lines · Jan Beulich
Quoted 9 lines · Juergen Gross
Commit
9dc46386d89d("gnttab: work around "may be used uninitialized" warning") was wrong, as vaddr can legitimately be NULL in caseXENMEM_resource_grant_table_id_statuswas specified for a grant table v1. This would result in crashes in debug builds due toASSERT_UNREACHABLE()triggering.Basically revert said commit, but keep returning
-ENODATAin that case.Fixes 9dc46386d89d ("gnttab: work around "may be used uninitialized"warning")
Quoted 13 lines
Quoted 13 lines
Signed-off-by Juergen Gross <[email protected]>---
Might be considered for 4.17 and for backporting--- xen/common/grant_table.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)xen/common/grant_table.c +0
-0@@ -4125,7 +4125,10 @@ int gnttab_acquire_resource(Quoted 8 lines
xen/common/grant_table.c int gnttab_acquire_resource( · line 4131
Quoted 6 lines
xen/common/grant_table.c +3
-0case XENMEM_resource_grant_table_id_status:if ( gt->gt_version !=2 ) + { + rc = -ENODATA ;break ; + }This path is supposed to produce
-EINVAL.Okay.
Quoted 7 lines
xen/common/grant_table.c int gnttab_acquire_resource( · line 4139
Quoted 7 lines
xen/common/grant_table.c +0
-2@@ -4135,17 +4138,6 @@ int gnttab_acquire_resource(break ; } -/* -* Some older toolchains can't spot that vaddrs won't remain uninitialized
Quoted 1 line
xen/common/grant_table.c int gnttab_acquire_resource( · line 4140
Quoted 1 line
xen/common/grant_table.c +0
-1-* on non-error paths, and hence it needs setting to NULL at the top of the
Quoted 5 lines
xen/common/grant_table.c int gnttab_acquire_resource( · line 4143
Quoted 3 lines
xen/common/grant_table.c +0
-3-* function. Leave some runtime safety. -*/ -if ( !vaddrs )I guess this wants amending by "&& !rc"?
I can do that, if you like that better.
Juergen
Quoted 4 lines · Henry Wang
Kind regards,
Henry
Hmm, did you mean to actually add some text in your message?
Jan
Hi Jan,
Quoted 8 lines
-----Original Message-----
Quoted 4 lines · Henry Wang
Kind regards,
HenryHmm, did you mean to actually add some text in your message?
I am really sorry, my outlook just got frozen and I must mis-send an empty email somehow. No nothing from my side.
Kind regards,
Henry
Quoted 2 lines
Jan
Quoted 49 lines · Juergen Gross
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Juergen Gross
Commit
9dc46386d89d("gnttab: work around "may be used uninitialized" warning") was wrong, as vaddr can legitimately be NULL in caseXENMEM_resource_grant_table_id_statuswas specified for a grant table v1. This would result in crashes in debug builds due toASSERT_UNREACHABLE()triggering.Basically revert said commit, but keep returning
-ENODATAin that case.Fixes 9dc46386d89d ("gnttab: work around "may be used uninitialized" warning")Signed-off-by Juergen Gross <[email protected]>---
Might be considered for 4.17 and for backporting
---
xen/common/grant_table.c| 14 +++-----------1 file changed, 3 insertions(+), 11 deletions(-)Quoted 13 lines
Quoted 11 lines
xen/common/grant_table.c +0
-0@@ -4125,7 +4125,10 @@ int gnttab_acquire_resource(case
XENMEM_resource_grant_table_id_status:
if (gt->gt_version!= 2 )
+ {
+ rc =-ENODATA;
break;
+ }This path is supposed to produce
-EINVAL.Okay.
Quoted 14 lines
Quoted 6 lines
xen/common/grant_table.c +0
-2@@ -4135,17 +4138,6 @@ int gnttab_acquire_resource( break; } - /* -* Some older toolchains can't spot that vaddrs won't remain Quoted 6 lines
uninitialized
- * on non-error paths, and hence it needs setting to NULL at the top of the
- * function. Leave some runtime safety.
- */
- if ( !vaddrs )I guess this wants amending by "&& !rc"?
Quoted 1 line
I can do that, if you like that better.
I would prefer that as well. Although I think it would be clear if we write
"
if ( rc )
return rc
else if ( !vaddrs )
"
Cheers,
Signature · 1 line
Julien Grall