Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3050494imm; Sun, 1 Jul 2018 11:05:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpefwHle5mZGEzMce1TUZ4HK4s1bwEowAtJPUB/OgWqZmLQgykZx9sy1go3fn98SmdGN4Tp3 X-Received: by 2002:a62:3101:: with SMTP id x1-v6mr22112022pfx.246.1530468313602; Sun, 01 Jul 2018 11:05:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530468313; cv=none; d=google.com; s=arc-20160816; b=TwTyeXBiRAtapcylqwnj1OJIzBB7bsjPQAjyl2vepU+Qdp29+Aq5SvgCzlWhxb0Qv+ p5AksFr70ae4q+TmPso1+IHK2i9SQdk3a55GjmCwkDhDJc9nooakNvwdD3BhW5D3/vqu 3YnyUgl9dqkJVetmKfuDBN85C0OBVcw1yObAYb6iDl0gOKG85xyFlYv5GCVu2ktztssd ySTfLdUsg4VWPRolM04g+GMqr/KCcf2X6ppA6hHnQ9Ee40iNuqXdGbl+nLZCfGNVITI+ mh21LCdT7NYa6EDxxQdGtnOc6+Xt6M8GM4V2jgpGOHEHHjrmuKnJ10Jep1lPM7u+Pk/y BZOw== 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=PwsxFAZWVmVxP02lIWlpSlCmYTEXlJ2Sz4CqVgFFpx8=; b=fJtqPMYljyHaNoEXXqsSXIuZwKR1jtGWJnr4SCu/cjtKW/RAMZ6w8uleqPwSqZahok 2hl/kjNWUgYceoxDL55Jcc8tVYUGu0rQyBUSLCFGZ/lqV/pAAnE8lwKFKY9aVo1ZbPbb W10jYz5oTPYBAAFTuOsMEYq85QKr2vnJGMKWQ2Ap2n2sWXP9WL0t39khfg11hBgWyJ3l 1RfYtKwbAJHT7XDVXHSAELy/dH56FK7LG7keZA9i4iTESjDhGp+zWeRwFvfyC5r+hfes 0IFnGE6SyBvatSP7H+ys/nbRzKBGSw82FSwgz++nheYHoCbUvto5rdqhQopY51+TK0p1 jMtQ== 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 l10-v6si14212206pfb.69.2018.07.01.11.04.59; Sun, 01 Jul 2018 11:05:13 -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 S1753476AbeGAQ3Y (ORCPT + 99 others); Sun, 1 Jul 2018 12:29:24 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34448 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933844AbeGAQ3I (ORCPT ); Sun, 1 Jul 2018 12:29:08 -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 89F4692B; Sun, 1 Jul 2018 16:29:07 +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.9 083/101] media: dvb_frontend: fix locking issues at dvb_frontend_get_event() Date: Sun, 1 Jul 2018 18:22:09 +0200 Message-Id: <20180701160800.482347008@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160757.138608453@linuxfoundation.org> References: <20180701160757.138608453@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.9-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 @@ -251,8 +251,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; @@ -270,13 +282,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;