Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2995592imm; Sun, 1 Jul 2018 09:58:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKILE8BjzrAedth1GZBqsXfQ8so6tdsiQyJLgAybx1fa3avnRkMeOEFWON1AYhcIziOev0Yy X-Received: by 2002:a17:902:9307:: with SMTP id bc7-v6mr22720280plb.292.1530464281271; Sun, 01 Jul 2018 09:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530464281; cv=none; d=google.com; s=arc-20160816; b=cEA36gdcQApg837dfE/qu4goIJ/UM7TJZfSKTEhaSR6RLFk+2RTXMY3mv7wBwP+rpf iKjS/YwI+dMJZ/QH2EqFB1xnaCKpLZprgEA62KAkHEXrwDmpxsJt9+3ORd9pSCWxDXqA wF9KFtva1cZhwV2CdEFwZXVp+dLTmPat2SNa/OdShJ/HqbFbS5V3BLgMMRgzbqyg5YXG 4b0+BmDfJBFG119wZ4CTzhbI5S1Ql4unCyLpweBP1ElrJQ7HtgR79BzkPxHFLwdL62go WabGy5nnGkzJlNPgWOTo+Gr/B6OWEqoGr+JhJvF2hzokG/ZXGHjKXw4pi2N/BEdsmkL7 jSPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=HO4rBRaM642IKHPFbGXmMEc/ZSeN7uvJvWB7rwbGOlY=; b=mUkFU5zd3z7iwRZwvzFFEAjyiMIpsM4g+jNiZzjMj2MiRSbXoF7bl74zoLkK+U7wS2 yVQlnaVBvLlRLO5aidNEex7RmrAoyyF/4/89Dr6LGhjHhuHKE2W4WcmIMOQo3vR3YaLw O32yFARPcWaaV/pVJmJjXTvaxLvjahu41YDXPYW0p311eIGzrLWNw6o7cdVl5tYxdOgW +xoog0Pt/9V3mwByjpw5ggqQlwqgDAanNYSmLakZaniDp61Er3sCOMqssryKUMMFvcoQ /KzHiWNYRd5fYndqOhjqxMX2AKrsQulcRz4WIui2krFdv+OdltsoKeiRfXQzXt69c7i8 Lq7g== 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 f5-v6si13699021plr.56.2018.07.01.09.57.47; Sun, 01 Jul 2018 09:58:01 -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 S1753627AbeGAQ4i (ORCPT + 99 others); Sun, 1 Jul 2018 12:56:38 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38120 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753661AbeGAQot (ORCPT ); Sun, 1 Jul 2018 12:44:49 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A19F8A73; Sun, 1 Jul 2018 16:44:48 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mauro Carvalho Chehab Subject: [PATCH 4.17 179/220] media: dvb_frontend: fix locking issues at dvb_frontend_get_event() Date: Sun, 1 Jul 2018 18:23:23 +0200 Message-Id: <20180701160915.700903478@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160908.272447118@linuxfoundation.org> References: <20180701160908.272447118@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.17-stable 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. Cc: stable@vger.kernel.org Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- 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 @@ -275,8 +275,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; @@ -294,13 +306,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;