Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp690825pxb; Fri, 16 Apr 2021 16:04:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0/9znCRfgYoG+KNAgj63VTVuDddX5loUxmNMOd0VMnt0Whxi3AwWBjD6r5Fa/0JXrZ9J1 X-Received: by 2002:a17:90b:30c3:: with SMTP id hi3mr11547711pjb.27.1618614283306; Fri, 16 Apr 2021 16:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618614283; cv=none; d=google.com; s=arc-20160816; b=JoLJ8ME7xIdvz3yQ5lj56Lyeb+L3IKzSRKQG9c411H3iO37Fp3VZtMnFd1eSVUGv2Y q3guP4PFIS8pVnin3g8PP9tl9qRqMWQ6sNCN9U8rb8i9qroxuyRlFVRN87jKqdkMAuDM 59Gs4zWiHYDRjDCat41GBr8dhgV+bWhm4bEU2zQHq3ikTbaXqIq+aHLAE42vRZ+aW0su rZOMB6kWS6h3H4jdypY/INM5R8p5p9PWL4EhNB8JOZJVUEpY6zpNND5WvSVcZ1qiR5kC 1mDMg2q1N3eq3JGTiH4+ymV6rgxwyuBv4FIyeJg+M+Jxz4hKfZ9KFV+kEwNQlETiRpAN olug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=mh7KPhLlx4lKOuec3qu70zVXkFr1yF2gQQ0PQcauUIE=; b=e84QsmcPKpLVfoHpPJHO/C64ty1kAvV7prznjeRn/Xhc2g2DFtEyEUevkRc4XXksd5 DKioJ7rzw98G1GfBlBphBZj+mBbKPS9A9KzSIdYYpxV28P8EYcRFNXfgAkT/7QBXcwzD xJtTG6AFjWYZGIgLWFGyDQo34BFmysU/qP7ek9jWt35E8jnSvlaamItwApeV+ysTOiDf S9vQFrjDt3OXmzcNRYVk9KqKZXzbft5avBGOvTxMAAfBIXJvRDNgzBM4ZmEfI2/MKIWl Nu5ciz9LTCEoYynZzfAL/p9j0lmW32k3scZ7K1tCUe4HEI5xWxKETHBJAqLsXe1NTAbi P8Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=UJFGZGUg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i5si8122041plt.332.2021.04.16.16.04.31; Fri, 16 Apr 2021 16:04:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=UJFGZGUg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234886AbhDPXDg (ORCPT + 99 others); Fri, 16 Apr 2021 19:03:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234856AbhDPXDd (ORCPT ); Fri, 16 Apr 2021 19:03:33 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40767C061756 for ; Fri, 16 Apr 2021 16:03:08 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id z5so7406378ioc.13 for ; Fri, 16 Apr 2021 16:03:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=mh7KPhLlx4lKOuec3qu70zVXkFr1yF2gQQ0PQcauUIE=; b=UJFGZGUgrqrrouEiWcHMIoZhuhTGc+Ot0YkymlGxKSqKbjNjVbjm4SiG6aWsMaJpta GTKzjQdXOagv58okSyt2i6YIPbt23iXeJ0uoDafPSYycAhNuVGEnfN5GPTc22QWZ78w9 /It3/bnDylnpJbRnLQV+OegtKBc+ea1J2KEAQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=mh7KPhLlx4lKOuec3qu70zVXkFr1yF2gQQ0PQcauUIE=; b=nlRvFw0eYZRZR3LJAycIEYb25rCZWQsFssbgJXoQDF6OkUsPrSQdxX7NjsC/tJ/mLS S4Ovu3cVjeawTJaJXmlEIz6SaGbElHeWKqWXb1xB7XueV4REoAqxeB6BPm57kC7PVAhV cOzT9NVcZVYveBBz1q+vahmkPYplXInE4zrY9QoHsDD5TZPditS6ywLrnc4H34aeqnD2 9EEAJTnU1/u/PzXLThGZTcrq/+GkicxWEdWG/PskJrwLHz59yPWc78NIspjdEecM0Mw9 +xer3gMvE4A5epJrVLQFlch+EPvfMLTmJpIElhMfjGLElKeANHNQGiEIXzcbRu53mdOx JohQ== X-Gm-Message-State: AOAM5329FmMBddz62ScyHZMLer0fxxqggBxnfJ4Ee08Wk2Os35VBP2zA VqcFXzAkFYwvMeVAiMZM39XWEQ== X-Received: by 2002:a02:9389:: with SMTP id z9mr6127773jah.60.1618614186189; Fri, 16 Apr 2021 16:03:06 -0700 (PDT) Received: from [192.168.1.112] (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id f8sm3417150ilr.20.2021.04.16.16.03.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Apr 2021 16:03:05 -0700 (PDT) Subject: Re: [PATCH RFC v3] media: em28xx: Fix race condition between open and init function To: Igor Torrente , mchehab@kernel.org Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, kernel test robot , syzbot+b2391895514ed9ef4a8e@syzkaller.appspotmail.com, Shuah Khan References: <20210415140724.15398-1-igormtorrente@gmail.com> From: Shuah Khan Message-ID: <49c44747-1f25-11a1-1132-abfe406955b2@linuxfoundation.org> Date: Fri, 16 Apr 2021 17:03:05 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/16/21 1:33 PM, Igor Torrente wrote: > > > On 4/15/21 2:25 PM, Shuah Khan wrote: >> On 4/15/21 8:07 AM, Igor Matheus Andrade Torrente wrote: >>> Fixes a race condition - for lack of a more precise term - between >>> em28xx_v4l2_open and em28xx_v4l2_init, by detaching the v4l2_dev, >>> media_pad and vdev structs from the em28xx_v4l2, and managing the >>> lifetime of those objects more dynamicaly. >>> >>> The race happens when a thread[1] - containing the em28xx_v4l2_init() >>> code - calls the v4l2_mc_create_media_graph(), and it return a error, >>> if a thread[2] - running v4l2_open() - pass the verification point >>> and reaches the em28xx_v4l2_open() before the thread[1] finishes >>> the deregistration of v4l2 subsystem, the thread[1] will free all >>> resources before the em28xx_v4l2_open() can process their things, >>> because the em28xx_v4l2_init() has the dev->lock. And all this lead >>> the thread[2] to cause a user-after-free. >>> >>> Reported-by: kernel test robot >>> Reported-and-tested-by: >>> syzbot+b2391895514ed9ef4a8e@syzkaller.appspotmail.com >>> Signed-off-by: Igor Matheus Andrade Torrente >>> --- >>> >>> V2: Add v4l2_i2c_new_subdev null check >>>      Deal with v4l2 subdevs dependencies >>> >>> V3: Fix link error when compiled as a module >>> >>> --- >>>   drivers/media/usb/em28xx/em28xx-camera.c |   4 +- >>>   drivers/media/usb/em28xx/em28xx-video.c  | 300 +++++++++++++++-------- >>>   drivers/media/usb/em28xx/em28xx.h        |   6 +- >>>   3 files changed, 209 insertions(+), 101 deletions(-) >>> >> >> The changes looks good to me. Have you tried building as a modules and >> running modprobes and rmmods? You can do that without a device. >> > > I tried and everything worked fine. > Thank you. Reviewed-by: Shuah Khan thanks, -- Shuah