Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3339566imu; Sun, 11 Nov 2018 12:44:02 -0800 (PST) X-Google-Smtp-Source: AJdET5fTraP4lgg1Nv86BHb/a36gmiRaEuOQwrbfQDoetecautcUTd8QRd8eHwB9KbaeaDsk9YkO X-Received: by 2002:a17:902:20eb:: with SMTP id v40-v6mr7876025plg.234.1541969042527; Sun, 11 Nov 2018 12:44:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541969042; cv=none; d=google.com; s=arc-20160816; b=oLRNQHPWibOeP0LNq7hcfzYnH77/Wf4xgK3zhYeSTpDPAHXApFnxJ/UAqg18DAkFlL EI/bPDnOv4b4ebJfXlpVAnczTnpzzoC7WsHB0ufBhOS93G643fVFk6h9Vx+/n/qZBAQf MhKa4jNVie/tUo6uOu4vpZwptNXhcAD4V1lcplUXDdfsNjOnmdRClN2KgI+Xt8G9jFVb k7SYnZrIs+n6mnjqsACm10hzZZnwY80MEsED0gaCRqX4k5GAhvWtztuzydgovHvQhF6f 2wuI9H0OJJpFrQTFTrJrtEvXjOR8NqP65tQ5EDwGQ48ODqi8l8yfYCXIvkriZRbTTNlq EuJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=37atA4gIpZUI0IWW5GjcHtIDAy6z9M9+Mj2A9hO7ATM=; b=hqywTL/4hcNZkMOJx+MbfIPk9oRPs85LsNroTYVr/jqdHNjM5cMC/YcI7fjV+388zT /uZCHm5lbaBYFwfvqJMS6MofK8zrI9M/CD8YxOa4UXsKDoBCX+hamzHQaFJIzJZ5Xs41 uWdc1LA2CwlfzOzN5b7f26hi/ZWiNzwpmj7K2nnAW7EuaTtl7105q8XEneUIooWZ7DVl 4pMpVUujFP6olxdlXcTv39S048NEnBjrlpDfsL5I8LqxCqqnGkwcNsdpSC5k/7ZqKB98 egsnI62yKPaQHfElCCUGi8h9VNFCidS+RsYwD9SgAoVveCtDJ0Hx9O87UsguVstluLcp MZcQ== 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 r14si4453167pgh.39.2018.11.11.12.43.47; Sun, 11 Nov 2018 12:44:02 -0800 (PST) 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 S1729807AbeKLFsC (ORCPT + 99 others); Mon, 12 Nov 2018 00:48:02 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:49298 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729563AbeKLFsB (ORCPT ); Mon, 12 Nov 2018 00:48:01 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsO-0000lM-2q; Sun, 11 Nov 2018 19:58:32 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsN-0001NT-SB; Sun, 11 Nov 2018 19:58:31 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Mauro Carvalho Chehab" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 018/366] media: dvb_frontend: fix locking issues at dvb_frontend_get_event() In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Mauro Carvalho Chehab commit 76d81243a487c09619822ef8e7201a756e58a87d upstream. As warned by smatch: drivers/media/dvb-core/dvb_frontend.c:314 dvb_frontend_get_event() warn: inconsistent returns 'sem:&fepriv->sem'. Locked on: line 288 line 295 line 306 line 314 Unlocked on: line 303 The lock implementation for get event is wrong, as, if an interrupt occurs, down_interruptible() will fail, and the routine will call up() twice when userspace calls the ioctl again. The bad code is there since when Linux migrated to git, in 2005. Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Ben Hutchings --- drivers/media/dvb-core/dvb_frontend.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) --- a/drivers/media/dvb-core/dvb_frontend.c +++ b/drivers/media/dvb-core/dvb_frontend.c @@ -229,8 +229,20 @@ static void dvb_frontend_add_event(struc wake_up_interruptible (&events->wait_queue); } +static int dvb_frontend_test_event(struct dvb_frontend_private *fepriv, + struct dvb_fe_events *events) +{ + int ret; + + up(&fepriv->sem); + ret = events->eventw != events->eventr; + down(&fepriv->sem); + + return ret; +} + static int dvb_frontend_get_event(struct dvb_frontend *fe, - struct dvb_frontend_event *event, int flags) + struct dvb_frontend_event *event, int flags) { struct dvb_frontend_private *fepriv = fe->frontend_priv; struct dvb_fe_events *events = &fepriv->events; @@ -248,13 +260,8 @@ static int dvb_frontend_get_event(struct if (flags & O_NONBLOCK) return -EWOULDBLOCK; - up(&fepriv->sem); - - ret = wait_event_interruptible (events->wait_queue, - events->eventw != events->eventr); - - if (down_interruptible (&fepriv->sem)) - return -ERESTARTSYS; + ret = wait_event_interruptible(events->wait_queue, + dvb_frontend_test_event(fepriv, events)); if (ret < 0) return ret;