drm/amdgpu: Annotate struct amdgpu_bo_list with __counted_by
Subsystems (2)
PATCH 1/1 drm/amdgpu: Annotate struct amdgpu_bo_list with __counted_by
Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
As found with Coccinelle[1], add __counted_by for struct amdgpu_bo_list. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +1 -1
@@ -84,6 +84,7 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,kref_init (&list->refcount); + list->num_entries = num_entries; array = list->entries;for (i =0 ; i < num_entries; ++i) {
@@ -129,7 +130,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp, } list->first_userptr = first_userptr; - list->num_entries = num_entries;sort (array, last_entry,sizeof (struct amdgpu_bo_list_entry ), amdgpu_bo_list_entry_cmp,NULL );
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h +1 -1
@@ -56,7 +56,7 @@ struct amdgpu_bo_list {*/ struct mutex bo_list_mutex; -struct amdgpu_bo_list_entry entries[]; + struct amdgpu_bo_list_entry entries[] __counted_by(num_entries); }; int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
Signature · 1 line
2.34.1
Quoted 10 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structamdgpu_bo_list. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier.
Quoted 14 lines
Cc Alex Deucher <[email protected]>Cc "Christian König" <[email protected]>Cc "Pan, Xinhui" <[email protected]>Cc David Airlie <[email protected]>Cc Daniel Vetter <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Cc Luben Tuikov <[email protected]>Cc Christophe JAILLET <[email protected]>Cc Felix Kuehling <[email protected]>Signed-off-by Kees Cook <[email protected]>
Signature · 2 lines
Regards, Luben
Quoted 38 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +1
-1@@ -84,6 +84,7 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,kref_init (&list->refcount); + list->num_entries = num_entries; array = list->entries;for (i =0 ; i < num_entries; ++i) {@@ -129,7 +130,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp, } list->first_userptr = first_userptr; - list->num_entries = num_entries;sort (array, last_entry,sizeof (struct amdgpu_bo_list_entry ), amdgpu_bo_list_entry_cmp,NULL );drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h +1
-1@@ -56,7 +56,7 @@ struct amdgpu_bo_list {*/ struct mutex bo_list_mutex; -struct amdgpu_bo_list_entry entries[]; + struct amdgpu_bo_list_entry entries[] __counted_by(num_entries); }; int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
Am 04.10.23 um 01:29 schrieb Kees Cook:
Quoted 10 lines
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structamdgpu_bo_list. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier.
Quoted 14 lines
Cc Alex Deucher <[email protected]>Cc "Christian König" <[email protected]>Cc "Pan, Xinhui" <[email protected]>Cc David Airlie <[email protected]>Cc Daniel Vetter <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Cc Luben Tuikov <[email protected]>Cc Christophe JAILLET <[email protected]>Cc Felix Kuehling <[email protected]>Signed-off-by Kees Cook <[email protected]>
Quoted 38 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +1
-1@@ -84,6 +84,7 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,kref_init (&list->refcount); + list->num_entries = num_entries; array = list->entries;for (i =0 ; i < num_entries; ++i) {@@ -129,7 +130,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp, } list->first_userptr = first_userptr; - list->num_entries = num_entries;sort (array, last_entry,sizeof (struct amdgpu_bo_list_entry ), amdgpu_bo_list_entry_cmp,NULL );drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h +1
-1@@ -56,7 +56,7 @@ struct amdgpu_bo_list {*/ struct mutex bo_list_mutex; -struct amdgpu_bo_list_entry entries[]; + struct amdgpu_bo_list_entry entries[] __counted_by(num_entries); }; int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
Alex Deucher
AppliedApplied. Thanks!
Alex
Quoted 68 lines · Christian König
Am 04.10.23 um 01:29 schrieb Kees Cook:
Quoted 10 lines
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structamdgpu_bo_list. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier.Quoted 14 lines
Cc Alex Deucher <[email protected]>Cc "Christian König" <[email protected]>Cc "Pan, Xinhui" <[email protected]>Cc David Airlie <[email protected]>Cc Daniel Vetter <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Cc Luben Tuikov <[email protected]>Cc Christophe JAILLET <[email protected]>Cc Felix Kuehling <[email protected]>Signed-off-by Kees Cook <[email protected]>Reviewed-by Christian König <[email protected]>Quoted 38 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +1
-1@@ -84,6 +84,7 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,kref_init (&list->refcount); + list->num_entries = num_entries; array = list->entries;for (i =0 ; i < num_entries; ++i) {@@ -129,7 +130,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp, } list->first_userptr = first_userptr; - list->num_entries = num_entries;sort (array, last_entry,sizeof (struct amdgpu_bo_list_entry ), amdgpu_bo_list_entry_cmp,NULL );drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h +1
-1@@ -56,7 +56,7 @@ struct amdgpu_bo_list {*/ struct mutex bo_list_mutex; -struct amdgpu_bo_list_entry entries[]; + struct amdgpu_bo_list_entry entries[] __counted_by(num_entries); }; int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,