diff options
author | Anton Volkov <avolkov@ispras.ru> | 2017-08-07 08:54:14 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-08-07 14:25:14 -0400 |
commit | b925ef37b0a152b0c06aa43bc9204d0116f676d7 (patch) | |
tree | ae634920cf42835cad86baddf89b06be3662510a | |
parent | ec2c6726322f0d270bab477e4904bf9496f70ee5 (diff) |
hysdn: fix to a race condition in put_log_buffer
The synchronization type that was used earlier to guard the loop that
deletes unused log buffers may lead to a situation that prevents any
thread from going through the loop.
The patch deletes previously used synchronization mechanism and moves
the loop under the spin_lock so the similar cases won't be feasible in
the future.
Found by by Linux Driver Verification project (linuxtesting.org).
Signed-off-by: Anton Volkov <avolkov@ispras.ru>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/isdn/hysdn/hysdn_proclog.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c index 7b5fd8fb1761..aaca0b3d662e 100644 --- a/drivers/isdn/hysdn/hysdn_proclog.c +++ b/drivers/isdn/hysdn/hysdn_proclog.c | |||
@@ -44,7 +44,6 @@ struct procdata { | |||
44 | char log_name[15]; /* log filename */ | 44 | char log_name[15]; /* log filename */ |
45 | struct log_data *log_head, *log_tail; /* head and tail for queue */ | 45 | struct log_data *log_head, *log_tail; /* head and tail for queue */ |
46 | int if_used; /* open count for interface */ | 46 | int if_used; /* open count for interface */ |
47 | int volatile del_lock; /* lock for delete operations */ | ||
48 | unsigned char logtmp[LOG_MAX_LINELEN]; | 47 | unsigned char logtmp[LOG_MAX_LINELEN]; |
49 | wait_queue_head_t rd_queue; | 48 | wait_queue_head_t rd_queue; |
50 | }; | 49 | }; |
@@ -102,7 +101,6 @@ put_log_buffer(hysdn_card *card, char *cp) | |||
102 | { | 101 | { |
103 | struct log_data *ib; | 102 | struct log_data *ib; |
104 | struct procdata *pd = card->proclog; | 103 | struct procdata *pd = card->proclog; |
105 | int i; | ||
106 | unsigned long flags; | 104 | unsigned long flags; |
107 | 105 | ||
108 | if (!pd) | 106 | if (!pd) |
@@ -126,21 +124,21 @@ put_log_buffer(hysdn_card *card, char *cp) | |||
126 | else | 124 | else |
127 | pd->log_tail->next = ib; /* follows existing messages */ | 125 | pd->log_tail->next = ib; /* follows existing messages */ |
128 | pd->log_tail = ib; /* new tail */ | 126 | pd->log_tail = ib; /* new tail */ |
129 | i = pd->del_lock++; /* get lock state */ | ||
130 | spin_unlock_irqrestore(&card->hysdn_lock, flags); | ||
131 | 127 | ||
132 | /* delete old entrys */ | 128 | /* delete old entrys */ |
133 | if (!i) | 129 | while (pd->log_head->next) { |
134 | while (pd->log_head->next) { | 130 | if ((pd->log_head->usage_cnt <= 0) && |
135 | if ((pd->log_head->usage_cnt <= 0) && | 131 | (pd->log_head->next->usage_cnt <= 0)) { |
136 | (pd->log_head->next->usage_cnt <= 0)) { | 132 | ib = pd->log_head; |
137 | ib = pd->log_head; | 133 | pd->log_head = pd->log_head->next; |
138 | pd->log_head = pd->log_head->next; | 134 | kfree(ib); |
139 | kfree(ib); | 135 | } else { |
140 | } else | 136 | break; |
141 | break; | 137 | } |
142 | } /* pd->log_head->next */ | 138 | } /* pd->log_head->next */ |
143 | pd->del_lock--; /* release lock level */ | 139 | |
140 | spin_unlock_irqrestore(&card->hysdn_lock, flags); | ||
141 | |||
144 | wake_up_interruptible(&(pd->rd_queue)); /* announce new entry */ | 142 | wake_up_interruptible(&(pd->rd_queue)); /* announce new entry */ |
145 | } /* put_log_buffer */ | 143 | } /* put_log_buffer */ |
146 | 144 | ||