Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1702976 > unrolled thread
| Started by | Anton Volkov <avolkov@ispras.ru> |
|---|---|
| First post | 2017-08-03 13:50 +0200 |
| Last post | 2017-08-07 20:30 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH] hysdn: fix to a race condition in put_log_buffer Anton Volkov <avolkov@ispras.ru> - 2017-08-03 13:50 +0200
Re: [PATCH] hysdn: fix to a race condition in put_log_buffer Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2017-08-03 14:10 +0200
[PATCH v2] hysdn: fix to a race condition in put_log_buffer Anton Volkov <avolkov@ispras.ru> - 2017-08-07 15:00 +0200
Re: [PATCH v2] hysdn: fix to a race condition in put_log_buffer David Miller <davem@davemloft.net> - 2017-08-07 20:30 +0200
| From | Anton Volkov <avolkov@ispras.ru> |
|---|---|
| Date | 2017-08-03 13:50 +0200 |
| Subject | [PATCH] hysdn: fix to a race condition in put_log_buffer |
| Message-ID | <uamNA-7Pj-9@gated-at.bofh.it> |
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>
---
drivers/isdn/hysdn/hysdn_proclog.c | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c
index 7b5fd8f..b152c6c 100644
--- a/drivers/isdn/hysdn/hysdn_proclog.c
+++ b/drivers/isdn/hysdn/hysdn_proclog.c
@@ -44,7 +44,6 @@ struct procdata {
char log_name[15]; /* log filename */
struct log_data *log_head, *log_tail; /* head and tail for queue */
int if_used; /* open count for interface */
- int volatile del_lock; /* lock for delete operations */
unsigned char logtmp[LOG_MAX_LINELEN];
wait_queue_head_t rd_queue;
};
@@ -102,7 +101,6 @@ put_log_buffer(hysdn_card *card, char *cp)
{
struct log_data *ib;
struct procdata *pd = card->proclog;
- int i;
unsigned long flags;
if (!pd)
@@ -126,21 +124,20 @@ put_log_buffer(hysdn_card *card, char *cp)
else
pd->log_tail->next = ib; /* follows existing messages */
pd->log_tail = ib; /* new tail */
- i = pd->del_lock++; /* get lock state */
- spin_unlock_irqrestore(&card->hysdn_lock, flags);
/* delete old entrys */
- if (!i)
- while (pd->log_head->next) {
- if ((pd->log_head->usage_cnt <= 0) &&
- (pd->log_head->next->usage_cnt <= 0)) {
- ib = pd->log_head;
- pd->log_head = pd->log_head->next;
- kfree(ib);
- } else
- break;
- } /* pd->log_head->next */
- pd->del_lock--; /* release lock level */
+ while (pd->log_head->next) {
+ if ((pd->log_head->usage_cnt <= 0) &&
+ (pd->log_head->next->usage_cnt <= 0)) {
+ ib = pd->log_head;
+ pd->log_head = pd->log_head->next;
+ kfree(ib);
+ } else
+ break;
+ } /* pd->log_head->next */
+
+ spin_unlock_irqrestore(&card->hysdn_lock, flags);
+
wake_up_interruptible(&(pd->rd_queue)); /* announce new entry */
} /* put_log_buffer */
--
2.7.4
[toc] | [next] | [standalone]
| From | Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> |
|---|---|
| Date | 2017-08-03 14:10 +0200 |
| Message-ID | <uan6W-8co-11@gated-at.bofh.it> |
| In reply to | #1702976 |
Hello!
On 08/03/2017 02:33 PM, Anton Volkov wrote:
> 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>
> ---
> drivers/isdn/hysdn/hysdn_proclog.c | 27 ++++++++++++---------------
> 1 file changed, 12 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c
> index 7b5fd8f..b152c6c 100644
> --- a/drivers/isdn/hysdn/hysdn_proclog.c
> +++ b/drivers/isdn/hysdn/hysdn_proclog.c
[...]
> else
> pd->log_tail->next = ib; /* follows existing messages */
> pd->log_tail = ib; /* new tail */
> - i = pd->del_lock++; /* get lock state */
> - spin_unlock_irqrestore(&card->hysdn_lock, flags);
>
> /* delete old entrys */
> - if (!i)
> - while (pd->log_head->next) {
> - if ((pd->log_head->usage_cnt <= 0) &&
> - (pd->log_head->next->usage_cnt <= 0)) {
> - ib = pd->log_head;
> - pd->log_head = pd->log_head->next;
> - kfree(ib);
> - } else
> - break;
> - } /* pd->log_head->next */
> - pd->del_lock--; /* release lock level */
> + while (pd->log_head->next) {
> + if ((pd->log_head->usage_cnt <= 0) &&
> + (pd->log_head->next->usage_cnt <= 0)) {
> + ib = pd->log_head;
> + pd->log_head = pd->log_head->next;
> + kfree(ib);
> + } else
> + break;
> + } /* pd->log_head->next */
Need {} in the *else* branch as *if* had them.
[...]
MBR, Sergei
[toc] | [prev] | [next] | [standalone]
| From | Anton Volkov <avolkov@ispras.ru> |
|---|---|
| Date | 2017-08-07 15:00 +0200 |
| Subject | [PATCH v2] hysdn: fix to a race condition in put_log_buffer |
| Message-ID | <ubPNx-8kD-29@gated-at.bofh.it> |
| In reply to | #1703000 |
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>
---
v2: Fixed coding style issues
drivers/isdn/hysdn/hysdn_proclog.c | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c
index 7b5fd8f..aaca0b3 100644
--- a/drivers/isdn/hysdn/hysdn_proclog.c
+++ b/drivers/isdn/hysdn/hysdn_proclog.c
@@ -44,7 +44,6 @@ struct procdata {
char log_name[15]; /* log filename */
struct log_data *log_head, *log_tail; /* head and tail for queue */
int if_used; /* open count for interface */
- int volatile del_lock; /* lock for delete operations */
unsigned char logtmp[LOG_MAX_LINELEN];
wait_queue_head_t rd_queue;
};
@@ -102,7 +101,6 @@ put_log_buffer(hysdn_card *card, char *cp)
{
struct log_data *ib;
struct procdata *pd = card->proclog;
- int i;
unsigned long flags;
if (!pd)
@@ -126,21 +124,21 @@ put_log_buffer(hysdn_card *card, char *cp)
else
pd->log_tail->next = ib; /* follows existing messages */
pd->log_tail = ib; /* new tail */
- i = pd->del_lock++; /* get lock state */
- spin_unlock_irqrestore(&card->hysdn_lock, flags);
/* delete old entrys */
- if (!i)
- while (pd->log_head->next) {
- if ((pd->log_head->usage_cnt <= 0) &&
- (pd->log_head->next->usage_cnt <= 0)) {
- ib = pd->log_head;
- pd->log_head = pd->log_head->next;
- kfree(ib);
- } else
- break;
- } /* pd->log_head->next */
- pd->del_lock--; /* release lock level */
+ while (pd->log_head->next) {
+ if ((pd->log_head->usage_cnt <= 0) &&
+ (pd->log_head->next->usage_cnt <= 0)) {
+ ib = pd->log_head;
+ pd->log_head = pd->log_head->next;
+ kfree(ib);
+ } else {
+ break;
+ }
+ } /* pd->log_head->next */
+
+ spin_unlock_irqrestore(&card->hysdn_lock, flags);
+
wake_up_interruptible(&(pd->rd_queue)); /* announce new entry */
} /* put_log_buffer */
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | David Miller <davem@davemloft.net> |
|---|---|
| Date | 2017-08-07 20:30 +0200 |
| Subject | Re: [PATCH v2] hysdn: fix to a race condition in put_log_buffer |
| Message-ID | <ubUWR-3Xj-11@gated-at.bofh.it> |
| In reply to | #1705473 |
From: Anton Volkov <avolkov@ispras.ru> Date: Mon, 7 Aug 2017 15:54:14 +0300 > 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> > --- > v2: Fixed coding style issues Applied.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web