Project

General

Profile

Actions

Feature #3324

closed

32: Locking a mutex twice or unlocking without prior locking

Added by Ilya Shchepetkov over 11 years ago. Updated about 11 years ago.

Status:
Closed
Priority:
Normal
Start date:
08/03/2012
Due date:
% Done:

0%

Estimated time:
Published in build:

Description

(copied from kernel-rules/rules/DRVRULES_en.trl)

Summary

You should not acquire or release the same mutex twice in the same process. All locked mutexes should be unlocked at finalization.

Description

There are several things you should watch for:

  1. Double-locking. Mutex-type object provides exclusive access to sections of executable code. Thus retrying to acquire the current mutex will inevitably lead to a deadlock-situation. Deadlocks should be avoided, hence no double locks should take place.
  2. Releasing an unlocked mutex.
  3. Leaving a mutex locked at finalization.

Example

void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev, unsigned long value)  
{  
    mutex_lock(&device_ctls_mutex); /*acquire the device_ctls_mutex*/  

    /* cancel the current workq request */  
    edac_device_workq_teardown(edac_dev); /* function acquires the lock device_ctls_mutex */  
    /* leads to a double lock */  

    /* restart the workq request, with new delay value */  
    edac_device_workq_setup(edac_dev, value);  
    ... 

Related issues 2 (2 open0 closed)

Related to Linux Driver Verification - Bug #785: Develop model 32_8 that takes into account mutex_lock_nested, etc.New02/03/2011

Actions
Is duplicate of Linux Kernel Safety RuleDB - Feature #1940: 032: Locking a mutex twice or unlocking without prior lockingNew10/25/2011

Actions
Actions #1

Updated by Ilya Shchepetkov over 11 years ago

Night tests have shown:

-driver=test-0032-drivers-media-video-cafe_ccic.tar.bz2;origin=external;kernel=linux-2.6.32.15;model=32_1;module=drivers/test-032-drivers-media-video-cafe_ccic/cafe_ccic.ko;main=ldv_main0_sequence_infinite_withcheck_stateful;verdict=unsafe
+driver=test-0032-drivers-media-video-cafe_ccic.tar.bz2;origin=external;kernel=linux-2.6.32.15;model=32_1;module=drivers/test-032-drivers-media-video-cafe_ccic/cafe_ccic.ko;main=ldv_main0_sequence_infinite_withcheck_stateful;verdict=unknown;RCV_status=fail;problems=Out_of_memory

I removed this file from the test set for a while. Commit f9dd2f7 of master branch.

Actions #2

Updated by Evgeny Novikov over 11 years ago

  • Status changed from New to Open
  • Assignee set to Evgeny Novikov
  • Priority changed from Normal to High

Aspect model 32_7a doesn't contain necessary model for mutex_lock_nested function. Plain model uses a special configuration (it undefines CONFIG_DEBUG_LOCK_ALLOC) that allows to avoid this because of mutex_lock_nested is a macro that is expanded as modeled mutex_lock function.

Actions #3

Updated by Evgeny Novikov over 11 years ago

Google provides me an interesting related issue... from our bugzilla. It's #785. So, actually it isn't so simple to model mutex_lock_nested properly. Simple treating it as mutex_lock leads to false positives (e.g. see error traces for unmodeled mutex_lock_nested and modeled mutex_lock_nested). BTW, using COMPLEX_ID in rerouting won't help since two mutexes are the same field of the same structure fc_lport.

Actions #4

Updated by Evgeny Novikov over 11 years ago

Commit 1462ea9 has removed one more driver that demonstrated nondetermined behavior:

-driver=kbdrivers--0032-2.6.31.6--test-0032-2.6.31.6-verdict-unsafe-drivers--usb--class--cdc-acm.c.tar.bz2;origin=external;kernel=linux-2.6.31.6;model=32_1;module=drivers/kbdrivers/0032-2.6.31.6/test-0032-2.6.31.6-verdict-unsafe-drivers--usb--class--cdc-acm.c/cdc-acm.ko;main=ldv_main0_sequence_infinite_withcheck_stateful;verdict=unsafe
+driver=kbdrivers--0032-2.6.31.6--test-0032-2.6.31.6-verdict-unsafe-drivers--usb--class--cdc-acm.c.tar.bz2;origin=external;kernel=linux-2.6.31.6;model=32_1;module=drivers/kbdrivers/0032-2.6.31.6/test-0032-2.6.31.6-verdict-unsafe-drivers--usb--class--cdc-acm.c/cdc-acm.ko;main=ldv_main0_sequence_infinite_withcheck_stateful;verdict=unknown;RCV_status=fail;problems=Exception

Actions #5

Updated by Ilya Shchepetkov over 11 years ago

Commit 8339999 has removed one more driver that demonstrated nondetermined behavior:

-driver=kbdrivers--0032-2.6.31.6--test-0032-2.6.31.6-verdict-unsafe-drivers--media--video--cafe_ccic.c.tar.bz2;origin=external;kernel=linux-2.6.31.6;model=32_1;module=drivers/kbdrivers/0032-2.6.31.6/test-0032-2.6.31.6-verdict-unsafe-drivers--media--video--cafe_ccic.c/cafe_ccic.ko;main=ldv_main0_sequence_infinite_withcheck_stateful;verdict=unsafe
+driver=kbdrivers--0032-2.6.31.6--test-0032-2.6.31.6-verdict-unsafe-drivers--media--video--cafe_ccic.c.tar.bz2;origin=external;kernel=linux-2.6.31.6;model=32_1;module=drivers/kbdrivers/0032-2.6.31.6/test-0032-2.6.31.6-verdict-unsafe-drivers--media--video--cafe_ccic.c/cafe_ccic.ko;main=ldv_main0_sequence_infinite_withcheck_stateful;verdict=unknown;RCV_status=fail;problems=Out_of_memory
Actions #6

Updated by Ilya Shchepetkov over 11 years ago

  • Subject changed from 32_1: Locking a mutex twice or unlocking without prior locking to 32: Locking a mutex twice or unlocking without prior locking

Commit a50a723 has added new model function kref_put_mutex in 32_7a.

Actions #7

Updated by Evgeny Novikov over 11 years ago

  • Priority changed from High to Normal
Actions #8

Updated by Alexey Khoroshilov about 11 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF