Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1650322pxy; Fri, 23 Apr 2021 13:20:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySBMe9jnyoyh7OfAawDxC0PdBH5ym553cxDV/xFsjhy7xoigQqryVw+/cxpJg78xcibblj X-Received: by 2002:a17:903:4101:b029:ea:fc8a:9adb with SMTP id r1-20020a1709034101b02900eafc8a9adbmr5416351pld.49.1619209229950; Fri, 23 Apr 2021 13:20:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619209229; cv=none; d=google.com; s=arc-20160816; b=wrbzT4hqWzrAfwY5lj5mSfsHDBoZ2usABqzw/G2yaoQdKc+l8lVwOoX6jSmzpopnzh 5iZy4Y5J+DuUFykmjb0a7KQrytitsF/3MmhjOAw2O/idkjhBF8JA6LcM8zzjG03adkWn Otl0yQ1g84eVd1ZW7ff25LYSsmpJZFhmcAOFJChxn+7FoYfLZTaVsrdl2RuiRwKyHESC asC/IyBi5ChOVteUowK/0tBbCbf46SPS+P0QoVqJWRDyIhkMf54TqX5quITB0xJj1uW4 hwpxTa/EGUt//RlGZqWI1Ifn4IAbz4QAnjBMiXFztJ3/9DmfSZAV92zrOgHrsXnojDyI buGg== 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=J1NPesUHck/PXytWUMZaL5H3tigSX17N3XIw4EegWTo=; b=lYzsR2Mp3PPlDJuf5VH6k7iZrVdk9+43FiS9VfcDjdKaop0qn6/g8SSe0JsCs4efX+ vxFoC4ik+FD0NU40IFkOIJsZKWzFvDIvBURl8PFSYTqj7otKGr6SD9cFlWVFYoDlEyq3 PQpaRdXiCuKvkRpTnJHyOLGH/W6EBGMvaOyO1iEFCURfNrh9NZtkks+0GzGHa2hBi2MQ eSqetjFvWQqqmrmxxz+oBuqWvyUMzGUMuHia7uaoVR7dcXqbuTQ6uD7K01dwOrFe1CHO sYCgOSsD/+9wdoggwl0YHiYnYNvrqYOaPb7MOaOTL9Fk984Cj938JASKP/VzDEdsh8T6 a3iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b="h/zj34eM"; 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 u1si7950945pgr.162.2021.04.23.13.20.17; Fri, 23 Apr 2021 13:20:29 -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="h/zj34eM"; 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 S232686AbhDWUT6 (ORCPT + 99 others); Fri, 23 Apr 2021 16:19:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231721AbhDWUT4 (ORCPT ); Fri, 23 Apr 2021 16:19:56 -0400 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8778C061574 for ; Fri, 23 Apr 2021 13:19:17 -0700 (PDT) Received: by mail-ot1-x32f.google.com with SMTP id f75-20020a9d03d10000b0290280def9ab76so41249476otf.12 for ; Fri, 23 Apr 2021 13:19:17 -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=J1NPesUHck/PXytWUMZaL5H3tigSX17N3XIw4EegWTo=; b=h/zj34eMbFVxnsOvC1DnFfdHinWG50GkumzwQGZ3MZu0ke7Lr1+JaFtFTDV5XOMqgb YRBq6VuCEXA8EBgdPhBKdI8oQ+W1EfSjN+mznToiU1mQ0PHbX7CJj/DLoXjr/0DPhu53 nqx6oFLPXP+PI2JuGA23gyWv8SY61CY5Ie7jE= 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=J1NPesUHck/PXytWUMZaL5H3tigSX17N3XIw4EegWTo=; b=HiuSz9tPcadPyfEfeVcedziwOgAFpcD6zEbMvBOC9Ke0oKfWis7xrMSlmLZgFGAEze 8P5/PTbUVqKbTQ+yfVXn89vueZdzGCevlKGIEztULU9r9P5aG308eDBBVYFd9p70/HfM wYT83HNWxMDxfD/NLZJ4VYtrFMoYZMzcnz33EfiBWJId4hyj5ZP0bCpY/9p2Z/6hw5qw gqewZfmrpjcCAvfWXv1k+BJ3F/wSiDiNwLf++Q1S3ZGREXU9/Jep+mo5GUrXHJFdfH/t ZEeOkpBS72tQL9fkn612fvGy4WuXIohrG3ncHj5wqVvdCV6RGx41Px38WyMgRFzfAKDt Gqmw== X-Gm-Message-State: AOAM533jNVj7mEHuqd8XuVF4be9XmJy8XUafNxwI2XWRk1iPcCICngur bMTPnVlzyqXLRRKDB8twO//HUA== X-Received: by 2002:a9d:6483:: with SMTP id g3mr4825315otl.332.1619209157176; Fri, 23 Apr 2021 13:19:17 -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 o20sm1364829oos.19.2021.04.23.13.19.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Apr 2021 13:19:16 -0700 (PDT) Subject: Re: [PATCH] media: gspca: stv06xx: Fix memleak in stv06xx subdrivers To: Pavel Skripkin , Atul Gopinathan Cc: syzbot+990626a4ef6f043ed4cd@syzkaller.appspotmail.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org, mchehab@kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-media@vger.kernel.org, Shuah Khan References: <20210422160742.7166-1-atulgopinathan@gmail.com> <20210422215511.01489adb@gmail.com> From: Shuah Khan Message-ID: <36f126fc-6a5e-a078-4cf0-c73d6795a111@linuxfoundation.org> Date: Fri, 23 Apr 2021 14:19:15 -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: <20210422215511.01489adb@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/22/21 12:55 PM, Pavel Skripkin wrote: > Hi! > > On Thu, 22 Apr 2021 21:37:42 +0530 > Atul Gopinathan wrote: >> During probing phase of a gspca driver in "gspca_dev_probe2()", the >> stv06xx subdrivers have certain sensor variants (namely, hdcs_1x00, >> hdcs_1020 and pb_0100) that allocate memory for their respective >> sensor which is passed to the "sd->sensor_priv" field. During the >> same probe routine, after "sensor_priv" allocation, there are chances >> of later functions invoked to fail which result in the probing >> routine to end immediately via "goto out" path. While doing so, the >> memory allocated earlier for the sensor isn't taken care of resulting >> in memory leak. >> >> Fix this by adding operations to the gspca, stv06xx and down to the >> sensor levels to free this allocated memory during gspca probe >> failure. >> >> - >> The current level of hierarchy looks something like this: >> >> gspca (main driver) represented by struct gspca_dev >> | >> ___________|_____________________________________ >> | | | | | | (subdrivers) >> | represented >> stv06xx by "struct >> sd" | >> _______________|_______________ >> | | | | | (sensors) >> | | >> hdcs_1x00/1020 pb01000 >> |_________________| >> | >> These three sensor variants >> allocate memory for >> "sd->sensor_priv" field. >> >> Here, "struct gspca_dev" is the representation used in the top level. >> In the sub-driver levels, "gspca_dev" pointer is cast to "struct sd*", >> something like this: >> >> struct sd *sd = (struct sd *)gspca_dev; >> >> This is possible because the first field of "struct sd" is >> "gspca_dev": >> >> struct sd { >> struct gspca_dev; >> . >> . >> } >> >> Therefore, to deallocate the "sd->sensor_priv" fields from >> "gspca_dev_probe2()" which is at the top level, the patch creates >> operations for the subdrivers and sensors to be invoked from the gspca >> driver levels. These operations essentially free the "sd->sensor_priv" >> which were allocated by the "config" and "init_controls" operations in >> the case of stv06xx sub-drivers and the sensor levels. >> >> This patch doesn't affect other sub-drivers or even sensors who never >> allocate memory to "sensor_priv". It has also been tested by syzbot >> and it returned an "OK" result. >> >> https://syzkaller.appspot.com/bug?id=ab69427f2911374e5f0b347d0d7795bfe384016c >> - >> >> Fixes: 4c98834addfe ("V4L/DVB (10048): gspca - stv06xx: New >> subdriver.") Cc: stable@vger.kernel.org >> Suggested-by: Shuah Khan >> Reported-by: syzbot+990626a4ef6f043ed4cd@syzkaller.appspotmail.com >> Tested-by: syzbot+990626a4ef6f043ed4cd@syzkaller.appspotmail.com >> Signed-off-by: Atul Gopinathan > > AFAIK, something similar is already applied to linux-media tree > https://git.linuxtv.org/media_tree.git/commit/?id=4f4e6644cd876c844cdb3bea2dd7051787d5ae25 > Pavel, Does the above handle the other drivers hdcs_1x00/1020 and pb01000? Atul's patch handles those cases. If thoese code paths need to be fixes, Atul could do a patch on top of yours perhaps? thanks, -- Shuah