ipc/sem.c: change perform_atomic_semop parameters
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 14 lines · Linux Kernel
Gitweb: http://git.kernel.org/linus/;a=commit;h=d198cd6d6d02d0a335af2deacb60816ebb4719d1 Commit: d198cd6d6d02d0a335af2deacb60816ebb4719d1 Parent: 2f2ed41dcaec34f2d6f224aa84efcc5a9dd8d5c3 Refname: refs/heads/next Author: Manfred Spraul <[email protected]> AuthorDate: Fri Jun 6 14:37:49 2014 -0700 Committer: Linus Torvalds <[email protected]> CommitDate: Fri Jun 6 16:08:15 2014 -0700
ipc/sem.c: changeperform_atomic_semopparametersRight now,
perform_atomic_semopgets the content ofsem_queueas individual fields. Changes that, instead pass a pointer tosem_queue.
Quoted 8 lines
This is a preparation for the next patch: it uses
sem_queueto store the reason why a task must sleep.Signed-off-by Manfred Spraul <[email protected]>Cc Davidlohr Bueso <[email protected]>Cc Michael Kerrisk <[email protected]>Signed-off-by Andrew Morton <[email protected]>Signed-off-by Linus Torvalds <[email protected]>
After this patch, coverity started complaining about a potential deref after null check. (It may have been a problem before, but the code motion causes a new 'event')
33. var_compare_op: Comparing un to null implies that un might be null.
1878 if (un && un->semid == -1)
1879 goto out_unlock_free;
1880
1881 queue.sops = sops;
1882 queue.nsops = nsops;
34. alias_transfer: Assigning: queue.undo = un.
1883 queue.undo = un; 1884 queue.pid = task_tgid_vnr(current); 1885 queue.alter = alter;
1886
CID 1222114 (#1 of 1): Dereference after null check (FORWARD_NULL)
35. var_deref_model: Passing &queue to perform_atomic_semop, which dereferences null queue.undo. [show details]
1887 error = perform_atomic_semop(sma, &queue);
Dave
Hi Dave,
Quoted 28 lines · Dave Jones
Quoted 14 lines · Linux Kernel
Gitweb: http://git.kernel.org/linus/;a=commit;h=d198cd6d6d02d0a335af2deacb60816ebb4719d1 Commit: d198cd6d6d02d0a335af2deacb60816ebb4719d1 Parent: 2f2ed41dcaec34f2d6f224aa84efcc5a9dd8d5c3 Refname: refs/heads/next Author: Manfred Spraul <[email protected]> AuthorDate: Fri Jun 6 14:37:49 2014 -0700 Committer: Linus Torvalds <[email protected]> CommitDate: Fri Jun 6 16:08:15 2014 -0700
ipc/sem.c: changeperform_atomic_semopparametersRight now,
perform_atomic_semopgets the content ofsem_queueas individual fields. Changes that, instead pass a pointer tosem_queue.Quoted 8 lines
This is a preparation for the next patch: it uses
sem_queueto store the reason why a task must sleep.Signed-off-by Manfred Spraul <[email protected]>Cc Davidlohr Bueso <[email protected]>Cc Michael Kerrisk <[email protected]>Signed-off-by Andrew Morton <[email protected]>Signed-off-by Linus Torvalds <[email protected]>After this patch, coverity started complaining about a potential deref after null check. (It may have been a problem before, but the code motion causes a new 'event')
Quoted 6 lines
33.
var_compare_op: Comparing un to null implies that un might be null.
1878 if (un &&un->semid== -1)
1879 gotoout_unlock_free;
1880
1881 queue.sops = sops;
1882 queue.nsops = nsops;
Correct, un can be NULL.
But only if sem_flg & SEM_UNDO is false for every operation:
from semtimedop():
Quoted 17 lines
Quoted 7 lines
if (sop->sem_flg & SEM_UNDO) undos = 1; [...] if (undos) { /* On success, find_alloc_undo takes the rcu_read_lock */ un = find_alloc_undo(ns, semid);Quoted 8 lines
if (IS_ERR(un)) { error = PTR_ERR(un); goto out_free; } } else { un = NULL; rcu_read_lock(); }
Quoted 5 lines
34.
alias_transfer: Assigning: queue.undo = un.1883 queue.undo = un; 1884 queue.pid = task_tgid_vnr(current); 1885 queue.alter = alter;1886
Correct.
Quoted 4 lines
CID 1222114 (#1 of 1): Dereference after null check (
FORWARD_NULL)
35.var_deref_model: Passing &queue toperform_atomic_semop, which dereferences null queue.undo. [show details]
1887 error =perform_atomic_semop(sma, &queue);
Passing &queue to perform_atomic_semop (correct),
which dereferences null queue.undo: Incorrect. queue.undo is only dereferenced if sem_flg&SEM_UNDO is true.
Thus: As far as I can see it's a false alarm.
And - even more simply: queue.un=NULL is the common case.
--
Manfred