* [PATCH][next] afs: fix a dereference on pointer cell before cell is null checked
@ 2020-10-21 13:11 Colin King
2020-10-27 11:05 ` David Howells
0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2020-10-21 13:11 UTC (permalink / raw)
To: David Howells, linux-afs; +Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
Currently the assignment of debug_id dereferences pointer cell before
cell has been null checked. Fix this by removing debug_id and use
cell->debug_id after cell has been null checked.
Addresses-Coverity: ("Dereference before null check")
Fixes: dca54a7bbb8c ("afs: Add tracing for cell refcount and active user count")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
fs/afs/cell.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/afs/cell.c b/fs/afs/cell.c
index 52233fa6195f..4449ff100a3c 100644
--- a/fs/afs/cell.c
+++ b/fs/afs/cell.c
@@ -589,7 +589,6 @@ struct afs_cell *afs_use_cell(struct afs_cell *cell, enum afs_cell_trace reason)
*/
void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_trace reason)
{
- unsigned int debug_id = cell->debug_id;
time64_t now, expire_delay;
int u, a;
@@ -606,7 +605,7 @@ void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_tr
u = atomic_read(&cell->ref);
a = atomic_dec_return(&cell->active);
- trace_afs_cell(debug_id, u, a, reason);
+ trace_afs_cell(cell->debug_id, u, a, reason);
WARN_ON(a = 0);
if (a = 1)
/* 'cell' may now be garbage collected. */
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] afs: fix a dereference on pointer cell before cell is null checked
2020-10-21 13:11 [PATCH][next] afs: fix a dereference on pointer cell before cell is null checked Colin King
@ 2020-10-27 11:05 ` David Howells
2020-10-27 11:18 ` Colin Ian King
0 siblings, 1 reply; 3+ messages in thread
From: David Howells @ 2020-10-27 11:05 UTC (permalink / raw)
To: Colin King; +Cc: dhowells, linux-afs, kernel-janitors, linux-kernel
Colin King <colin.king@canonical.com> wrote:
> @@ -606,7 +605,7 @@ void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_tr
>
> u = atomic_read(&cell->ref);
> a = atomic_dec_return(&cell->active);
> - trace_afs_cell(debug_id, u, a, reason);
> + trace_afs_cell(cell->debug_id, u, a, reason);
It's probably better to read cell->debug_id before calling
atomic_dec_return().
I have a patch for this based on a report by Dan Carpenter, so no need to send
a revised patch.
Thanks,
David
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] afs: fix a dereference on pointer cell before cell is null checked
2020-10-27 11:05 ` David Howells
@ 2020-10-27 11:18 ` Colin Ian King
0 siblings, 0 replies; 3+ messages in thread
From: Colin Ian King @ 2020-10-27 11:18 UTC (permalink / raw)
To: David Howells; +Cc: linux-afs, kernel-janitors, linux-kernel
On 27/10/2020 11:05, David Howells wrote:
> Colin King <colin.king@canonical.com> wrote:
>
>> @@ -606,7 +605,7 @@ void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_tr
>>
>> u = atomic_read(&cell->ref);
>> a = atomic_dec_return(&cell->active);
>> - trace_afs_cell(debug_id, u, a, reason);
>> + trace_afs_cell(cell->debug_id, u, a, reason);
>
> It's probably better to read cell->debug_id before calling
> atomic_dec_return().
>
> I have a patch for this based on a report by Dan Carpenter, so no need to send
> a revised patch.
OK - thanks David
>
> Thanks,
> David
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-10-27 11:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-21 13:11 [PATCH][next] afs: fix a dereference on pointer cell before cell is null checked Colin King
2020-10-27 11:05 ` David Howells
2020-10-27 11:18 ` Colin Ian King
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).