Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751718AbdG0QTJ (ORCPT ); Thu, 27 Jul 2017 12:19:09 -0400 Received: from mail.ispras.ru ([83.149.199.45]:43582 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751626AbdG0QTF (ORCPT ); Thu, 27 Jul 2017 12:19:05 -0400 From: Anton Volkov To: isdn@linux-pingi.de Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org, khoroshilov@ispras.ru Subject: Possible race in hysdn.ko Message-ID: <8178d591-2b1a-334d-fdd1-4c6b98abad72@ispras.ru> Date: Thu, 27 Jul 2017 19:19:03 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1565 Lines: 40 Hello. While searching for races in the Linux kernel I've come across "drivers/isdn/hysdn/hysdn.ko" module. Here is a question that I came up with while analysing results. Lines are given using the info from Linux v4.12. In hysdn_proclog.c file in put_log_buffer function a non-standard type of synchronization is employed. It uses pd->del_lock as some kind of semaphore (hysdn_proclog.c: lines 129 and 143). Consider the following case: Thread 1: Thread 2: hysdn_log_write -> hysdn_add_log -> put_log_buffer spin_lock() hysdn_conf_open i = pd->del_lock++ -> hysdn_add_log spin_unlock() -> put_log_buffer if (!i) spin_lock() pd->del_lock-- i = pd->del_lock++ spin_unlock() if (!i) pd->del_lock-- - the loop that deletes unused buffer entries (hysdn_proclog.c: lines 134-142). pd->del_lock-- is not an atomic operation and is executed without any locks. Thus it may interfere in the increment process of pd->del_lock in another thread. There may be cases that lead to the inability of any thread going through the . I see several possible solutions to this problem: 1) move the under the spin_lock and delete pd->del_lock synchronization; 2) wrap pd->del_lock-- with spin_lock protection. What do you think should be done about it? Thank you for your time.