Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5184565imm; Tue, 12 Jun 2018 04:05:15 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJOhM5BG14Sj7eC9aga8ZFgkkHWRNLeR8i4yfBcMjQoPTatQmVLGfi76UNZn8UNiaARUard X-Received: by 2002:a63:778b:: with SMTP id s133-v6mr2741466pgc.400.1528801515470; Tue, 12 Jun 2018 04:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528801515; cv=none; d=google.com; s=arc-20160816; b=QRBKgs2znKTbgkTTtX7DDB9wHktzHmqC4deElvJKYHd0ovo0Zhe4wnKZHDR6MjuXbN C+9CsIob7/wOcE0V9Fcg4dyD+k3o69fklG+2y4FQ7oGCpnudtXkmJCWKXWNAC7n4dRVB sewV8+tszejFb5Caynu2npUZj0/4OaCXXecBgLrLIgULGd+eK4ACaMPBjwsLaMSXkPK3 f521Vm7WPiIFN57UdINa33t9qG3hgXXV2rJcXmv6Wp+2culwhJyfIbpC4D9NnN575R+x FTuKZpsLMhAkQ7CnrtnXtCbubAvLbcC1SPzZKXoQVAptTOuCOHoboibMQ8ILeQWAtbSN l7QQ== 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:dkim-signature:arc-authentication-results; bh=UeSv2U84AUAYThVZf28vmDow2HKXUVFBSN9B9dNQ/qE=; b=cAQaK9QUjBGUxSz5cPkvhXbejVFK2C55Ldqx2DrbG3tkrIb2EJil76aBQi9FrstD+6 Lb86SSdrNBh6O83eBXy7kAEyk6OCN9ZSqBupCJtZlQK8uyite8FSU9BsbLhpHROP4lQ0 zV4K8Qdq259YhjYGnqKQ/rh4P1LbEzKM1dWyXdhXJXdqjYu6pIQ9vUNQqDHCjMb7E6fc VHQaBERzBR8H3skr7wJnCm7MpV0+ZqKAOcvhzBs8VJkZYQM2o0t0gHBkMBQrv40FWCvK rfRvSbEyQ3ihhlGUv0xNSuOIDYE+6LVrTpTrhJis1Jm6w7LE7LrA6vWFd+eD1HXRyEgz EntQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=es47VBvp; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s84-v6si628769pfg.175.2018.06.12.04.05.01; Tue, 12 Jun 2018 04:05:15 -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; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=es47VBvp; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933508AbeFLLDT (ORCPT + 99 others); Tue, 12 Jun 2018 07:03:19 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:37662 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933308AbeFLLCw (ORCPT ); Tue, 12 Jun 2018 07:02:52 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5CB19bs036618; Tue, 12 Jun 2018 11:02:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=UeSv2U84AUAYThVZf28vmDow2HKXUVFBSN9B9dNQ/qE=; b=es47VBvprEeybrTgjWefC0GL3uI+HGhHqWS8Ma0hFavRjBvUP93fIp2OKFt3rVnh3n6L BdxGyYXFP3Z4CHY0SL6z6XDQHGjDBkrpXTIk5LGkbV/3ICscfFFWJziUM4J1xT5VVG8y 9FsGrFuXgJTxQCE7OwczMILFiEugZt1frVqB/Mt5E0MilLtjdwJuPP/yYr6Yx3lkvw+2 HJyYL+AuUNo7M8XLBJAlsmrt8/ni0TQgQUkNeG9AxIb7f/9UWcrOEJPYRLzHSCtn0rOD GCRLYEK2DHuBbhgrB3kVs+U+b1nXSBoJGJmKqk10N1Vdo1oBoAdeRtwMAfeBQqBumg0u xg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2jgecxgqdf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Jun 2018 11:02:42 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w5CB2fZS019986 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Jun 2018 11:02:41 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w5CB2cPP008921; Tue, 12 Jun 2018 11:02:38 GMT Received: from mwanda (/197.157.0.30) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 12 Jun 2018 04:02:38 -0700 Date: Tue, 12 Jun 2018 14:02:30 +0300 From: Dan Carpenter To: Hugo Lefeuvre Cc: Greg Kroah-Hartman , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: Re: [PATCH] staging: pi433: add mutex fixing race condition when accessing tx_cfg Message-ID: <20180612110230.dvqmcyisdwaynixj@mwanda> References: <20180612011200.GB1794@hle-laptop.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180612011200.GB1794@hle-laptop.local> User-Agent: NeoMutt/20170609 (1.8.3) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8921 signatures=668702 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=770 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806120130 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 11, 2018 at 09:12:00PM -0400, Hugo Lefeuvre wrote: > In the PI433_IOC_WR_TX_CFG case in pi433_ioctl, instance->tx_cfg is > modified using > > copy_from_user(&instance->tx_cfg, argp, sizeof(struct pi433_tx_cfg))) > > without any kind of synchronization. In the case where two threads > would execute this same command concurrently the tx_cfg field might > enter in an inconsistent state. > > Add a mutex making sure that the PI433_IOC_WR_TX_CFG case will never > be run by several threads concurrently. > > Signed-off-by: Hugo Lefeuvre We read the data from the user here and then we write it to the fifo in pi433_write(). We should be using the device->tx_fifo_lock so that we don't copy over the data at the same time we're writing it to the fifo. This bug could cause a user space program to fail. regards, dan carpenter