Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2113666imm; Thu, 7 Jun 2018 05:46:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKcwiWdMUYOlWg/6HkZ8sgm73+wA9vCWLcfisvl2aQtdxqXDa+JJxSGztEcoW5F33oaJltT X-Received: by 2002:a62:98c9:: with SMTP id d70-v6mr1682425pfk.195.1528375572416; Thu, 07 Jun 2018 05:46:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528375572; cv=none; d=google.com; s=arc-20160816; b=RNIUHjvm8nDc7Oxs/GQQEJdwNAGf1vz9IMBjcB5nsN7YjTUvrranShjWc9oP26CHb2 vgMZEnHwyK+B8fGR/DWZNHUMK0aeW/ju2YXfg8jsB22sqlRHOTF+yKzyS3pULQKBpE2a OrtNu6hke4pdp2DJfC/OJyjv7SrELbs1NvptfMrsNxnerHETVplNAvn1Dsch22i/MJGR xjc13pCkVMS0vrChfLVey6w4rEdLMVZ7n30AVW2GZp/hP1RRcHDM6jmC+LwBVec02ybR H2Dkz+j0BiCj9hWGRrIQ/LdSUzC7bJsunTXu2wW5qdA50k5eEPJrirf/PsfkMT1TO2Wx cmyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=sa00FiwseAxfqYV5gzEDacdh4CJu8Qr4xU0f7kJukEs=; b=u2N7s7tsDum54pc+XtKyoQuawUYx1FxHqc98MUVMjPHlF3w875NS5SsAzxegHHSeKU ZsexFPscGPyFo+IybWW0UBu9kHJZ+M8nUz9eGXYaC1pWCjGQvT2gyUYvv9VAEVieSd8N usUZ2FYKEyYV4moy23b/BfncuJn84sByzyCOzt9ywrywYFHQ6JQ1TvuWrWxXMtTaDtWJ Zla35x+TKPRMXAtJ7/6d7O6AYx61AOj1trdw9EKsf5MJG1w78JZ58jbib42zOh4RcAM8 Ci+HeUz/PJ6wI3p6j2dbePgYpiZaBStAGUR2w4FDF+sWoqkMp2T00VYKFvyCKORP0G0/ fczA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a13-v6si27793850pgv.158.2018.06.07.05.45.57; Thu, 07 Jun 2018 05:46:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753550AbeFGMpJ (ORCPT + 99 others); Thu, 7 Jun 2018 08:45:09 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:52021 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753365AbeFGMpI (ORCPT ); Thu, 7 Jun 2018 08:45:08 -0400 X-Originating-IP: 96.22.60.141 Received: from localhost (modemcable141.60-22-96.mc.videotron.ca [96.22.60.141]) (Authenticated sender: hle@owl.eu.com) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 4E32D60014; Thu, 7 Jun 2018 14:45:04 +0200 (CEST) Date: Thu, 7 Jun 2018 08:45:03 -0400 From: Hugo Lefeuvre To: Greg Kroah-Hartman Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: Re: [PATCH v2] staging: pi433: add mutex fixing concurrency issues. Message-ID: <20180607124216.GA2329@hle-laptop.local> References: <20180602175649.GA2816@hle-laptop.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180602175649.GA2816@hle-laptop.local> User-Agent: Mutt/1.10.0 (2018-05-17) X-Spam-Level: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > Add a mutex fixing a potential NULL pointer dereference in the pi433 > driver. > > If pi433_release and pi433_ioctl are concurrently called, > pi433_release might set filp->private_data to NULL while pi433_ioctl > is still accessing it, leading to NULL pointer dereference. This issue > might also affect pi433_write and pi433_read. > > The newly introduced mutex makes sure that instance data > will not be modified simultaneously by pi433_release, pi433_write, > pi433_read or pi433_ioctl. > > The mutex is stored in a newly introduced struct pi433_data, which > wraps struct pi433_instance and its mutex. > > Make filp->private_data point to a struct pi433_data, allowing to > acquire the lock before accessing the struct pi433_instance. > > Signed-off-by: Hugo Lefeuvre > --- > Changes in v2: > - Use mutex instead of rw semaphore. > - Introduce struct pi433_data in order to allow functions to lock > before dereferencing instance pointer. > - Make filp->private_data point to a struct pi433_data. > - Add missing braces. After discussing this issue on the kernel newbies mailing list[0] we came to the conclusion that it is very unlikely that pi433_release and pi433_ioctl would ever run concurrently in this case. This is also true for read/write. Unless one can find a situation where this might happen, I think we should not add this potentially unnecessary lock. Regards, Hugo [0] http://lists.kernelnewbies.org/pipermail/kernelnewbies/2018-June/019131.html -- Hugo Lefeuvre (hle) | www.owl.eu.com 4096/ 9C4F C8BF A4B0 8FC5 48EB 56B8 1962 765B B9A8 BACA