Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp10458240rwr; Fri, 12 May 2023 08:22:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5nJuU33rn0M9WH51+PKmQDEOj5VTkkTTCpLDUz3l1kNSt1goP/GiA+uAXe5D97qoUe7iS1 X-Received: by 2002:a05:6a20:7345:b0:da:d4eb:9e07 with SMTP id v5-20020a056a20734500b000dad4eb9e07mr29471363pzc.30.1683904977480; Fri, 12 May 2023 08:22:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683904977; cv=none; d=google.com; s=arc-20160816; b=VqYCpws+4GNrK0FPZbsUcdc1Mfzy3EIB0CfHEiS9TA96lwrK6NHoqDNuTL/FLSODtG poeKHlcv4XWhU+jkMxrkZB5aBcMAID79ddbWZjum+Bop3A2parNRlTPBTaq0hYe+2V/M XY2VWXHfU97RLclV5ZWQpu01T5mITe3sGmdShCw/agwA1/gWSQ1hxJMaz+2VzqmGSBrj pcrV2i8frWqR1ZAmBjqfX1tyEuNvtGVG8Oqx72ToR5RyM7etidWuB7s0q2FVPZzXmFyC YnsTweLvM1qBXjPxy+0SU4ROtIBeTEGKIsT9vkuk1/JID6OqNYpmiJz0QLJW4hzKUygc 5lnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=yBC/2fd/pTy86f/RktUSIjhL7D6eoxeTxbi9SGU6AMA=; b=ivVjWYP2F1AQlVZIIgR1rf7UJ7WSnrpuys9A4PWqlkfS87i/c1YDio7gHvHh1dImu5 JrDu2SwRi2iFiRRO7DdVeOZewzIuuDwhJhZXVth4x/wT3AFEDXMBn1R7u5HUuMj0GEgM RKsvx1qOdeoZHCirjHXTar0zwDtmAicylnhKDnVyeWhSBOriC7bPttQ+u/AgjNGyp8+s cJflOgZsZIQMFHWOgBU+mfTpmL7lovMnWjfgd/RR2gKYfUdOLW7Yc0XyXo1krf+F79BK uXPHwNf20V8gJLQbFSNu6jArqebFg5cVBpElgXll56Rd6gqaUJV6AlmrhcBnvf5Y4uJM uFiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=xi0Gf5fI; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="P48ggim/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v184-20020a6389c1000000b0051f00f9c18fsi9377560pgd.760.2023.05.12.08.22.45; Fri, 12 May 2023 08:22:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=xi0Gf5fI; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="P48ggim/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241762AbjELPSF (ORCPT + 99 others); Fri, 12 May 2023 11:18:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241720AbjELPSE (ORCPT ); Fri, 12 May 2023 11:18:04 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EC58FC; Fri, 12 May 2023 08:18:03 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2C39322238; Fri, 12 May 2023 15:18:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1683904682; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=yBC/2fd/pTy86f/RktUSIjhL7D6eoxeTxbi9SGU6AMA=; b=xi0Gf5fIWSW7F/xncP/LovqgLIxfJPwV478Mvrx44nOxjpARKDVHV8rs3wzLLb0BOV5U5W WvH0U00mRnJE+63qG/xf9PZZm8Qay3c7DNMGo8fTXBSP4qgrvCEdaPvm3MSQztxwf9dl7E 4STRohB7J5PDhelsQpV7OfIv0GwnYX4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1683904682; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=yBC/2fd/pTy86f/RktUSIjhL7D6eoxeTxbi9SGU6AMA=; b=P48ggim/OxM4TA3V2ZtMPH+ePpS6P+LFi92WgIm5AWPZlJUKrJ4DPpFeNhKRQ2k9iNU57b Gqp3wmJEFTOL6mCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0586513466; Fri, 12 May 2023 15:18:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id uSZRAKpYXmShdAAAMHmgww (envelope-from ); Fri, 12 May 2023 15:18:02 +0000 From: Takashi Iwai To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] media: dvb-core: Fix kernel WARNING for blocking operation in wait_event*() Date: Fri, 12 May 2023 17:18:00 +0200 Message-Id: <20230512151800.1874-1-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using a semaphore in the wait_event*() condition is no good idea. It hits a kernel WARN_ON() at prepare_to_wait_event() like: do not call blocking ops when !TASK_RUNNING; state=1 set at prepare_to_wait_event+0x6d/0x690 For avoiding the potential deadlock, rewrite to an open-coded loop instead. Unlike the loop in wait_event*(), this uses wait_woken() after the condition check, hence the task state stays consistent. CVE-2023-31084 was assigned to this bug. Reported-by: Yu Hao Link: https://lore.kernel.org/r/CA+UBctCu7fXn4q41O_3=id1+OdyQ85tZY1x+TkT-6OVBL6KAUw@mail.gmail.com/ Signed-off-by: Takashi Iwai --- drivers/media/dvb-core/dvb_frontend.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c index cc0a789f09ae..9293b058ab99 100644 --- a/drivers/media/dvb-core/dvb_frontend.c +++ b/drivers/media/dvb-core/dvb_frontend.c @@ -293,14 +293,22 @@ static int dvb_frontend_get_event(struct dvb_frontend *fe, } if (events->eventw == events->eventr) { - int ret; + struct wait_queue_entry wait; + int ret = 0; if (flags & O_NONBLOCK) return -EWOULDBLOCK; - ret = wait_event_interruptible(events->wait_queue, - dvb_frontend_test_event(fepriv, events)); - + init_waitqueue_entry(&wait, current); + add_wait_queue(&events->wait_queue, &wait); + while (!dvb_frontend_test_event(fepriv, events)) { + wait_woken(&wait, TASK_INTERRUPTIBLE, 0); + if (signal_pending(current)) { + ret = -ERESTARTSYS; + break; + } + } + remove_wait_queue(&events->wait_queue, &wait); if (ret < 0) return ret; } -- 2.35.3