Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp387217pxf; Thu, 25 Mar 2021 06:32:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw981K3qJja0IPAQEVlCEBLW9Cr7gyHJ4DEFI1zFRdDuLd6NFcBQBbftwj/ZltlbQxZK1n6 X-Received: by 2002:a17:906:1494:: with SMTP id x20mr9403659ejc.101.1616679127161; Thu, 25 Mar 2021 06:32:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616679127; cv=none; d=google.com; s=arc-20160816; b=ceu/A3IXzJhT0wL5XfRiej0hfoDUWVWnbW4Qk8Wo7s1tfBDyg4txfxP3iHkv+5Inp2 sBnnTBmClvkckf0JfZ16dDBgbxSXvSd01njJRhFz7F7EkXNhZpRquC2RYPLgGbiOCybP S+wWPhG55XuJaTXQRoBpFdEkG9jOmRgt+IjB8+SByPD/NPXYHcSqJ2vud0Xrd7FvUHth dzbqe48giLbq+cs82YFwG8d3sTrjx+71eb9FqD9uJ1hNvYDNDuwM52V0kHGO7M02gaAa G1B8oH+hvQZe5HH0g8QccZGS3wah8C9Fe7ocVfzUDobR6KoW6Zk15vsWVDdSX58CE4Im 7etQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=1KxpzHpBzHIIR0d4+mLxk0ks65hJp0uLAyGQBVQSIeU=; b=NAhVdPbeT9/ML9YgvZ/CJpqVyp7IsiB1Ihca+L0OXI0ystt1oCDFmv1bseoUYsFdcW CTZBt1tfGz/g8WO8MtFyr1VYVImrFPCo/W/jxiGlBTTWp86rwW0k+Ugn4VOWNouDcJST f+b7l/BG1F1ZX0aln3AI68pY31VJyl/AyO5KiwsrRXmPISv1Wcj003LNWD54jgt5gftm dOW/B7KoBzGjPT5E1g0f7x+yCDEfVwXmDp2COBSWOzDYBz5dqqJ8gyxOIEviiK0X2Ng/ wj/LOyAJAOnw/SANdTEI2iDqARHUF9eEUbF3bzpn2sFDfkzwArku61Y46FxWYR9Ft4rT XTdA== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n22si4277890eju.124.2021.03.25.06.31.42; Thu, 25 Mar 2021 06:32:07 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230133AbhCYNaq (ORCPT + 99 others); Thu, 25 Mar 2021 09:30:46 -0400 Received: from mail-wm1-f41.google.com ([209.85.128.41]:56306 "EHLO mail-wm1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229869AbhCYNaj (ORCPT ); Thu, 25 Mar 2021 09:30:39 -0400 Received: by mail-wm1-f41.google.com with SMTP id 12so1177540wmf.5; Thu, 25 Mar 2021 06:30:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=1KxpzHpBzHIIR0d4+mLxk0ks65hJp0uLAyGQBVQSIeU=; b=iVj+00kb7wVQood9ljjGeRAmPkYTvdKdhEJE7+DWUZsdj+mP6SwxqMQcb89U120V1C rgAqsrbG4UJKmGUH6ehyvcoVk2NAMKzI9APEOI0XWJt1t31apWh/UZye7qtAILZNvhAa UfNjmBYNnjAVyv2XCfFPluz97uDipAgbivw932doD0QahVv5irrwmK6W/lKejI7r25Zs um2aoIqiRnbQHkPvMDGOFrVeHDaD4nogFT8U0RE5VShGWdcQux0qto/fxX/2NfyEB3T2 yYBsrJsxa/dbnYp0Jlje3xB5mYoXg9+XReamQvSzMFhO5UgtGAarpBRLsWvRcqqhftCI 7xmQ== X-Gm-Message-State: AOAM533ddLkDXI/uAk3VBGuSG1RNlmxmjmr6Ve4EYRW9DeihuPyRPO2n TRM/jpIw1EWffjvPuBacBC2rAOIWhqg= X-Received: by 2002:a7b:ca44:: with SMTP id m4mr8045770wml.103.1616679038124; Thu, 25 Mar 2021 06:30:38 -0700 (PDT) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id d18sm7685472wra.8.2021.03.25.06.30.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 06:30:37 -0700 (PDT) Date: Thu, 25 Mar 2021 13:30:36 +0000 From: Wei Liu To: Michael Kelley Cc: Lv Yunlong , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , "wei.liu@kernel.org" , "linux-hyperv@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "linux-fbdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2] video: hyperv_fb: Fix a double free in hvfb_probe Message-ID: <20210325133036.rbriezf3v32wofkl@liuwe-devbox-debian-v2> References: <20210324103724.4189-1-lyl2019@mail.ustc.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 24, 2021 at 01:46:39PM +0000, Michael Kelley wrote: > From: Lv Yunlong Sent: Wednesday, March 24, 2021 3:37 AM > > > > In function hvfb_probe in hyperv_fb.c, it calls hvfb_getmem(hdev, info) > > and return err when info->apertures is freed. > > > > In the error1 label of hvfb_probe, info->apertures will be freed for the > > second time in framebuffer_release(info). > > > > My patch removes all kfree(info->apertures) instead of set info->apertures > > to NULL. It is because that let framebuffer_release() handle freeing the > > memory flows the fbdev pattern, and less code overall. > > Let me suggest some clarifications in the commit message. It's probably > better not to reference the initial approach of setting info->apertures to > NULL, since there won't be any record of that approach in the commit > history. Here's what I would suggest: > > Function hvfb_probe() calls hvfb_getmem(), expecting upon return that > info->apertures is either NULL or points to memory that should be freed > by framebuffer_release(). But hvfb_getmem() is freeing the memory and > leaving the pointer non-NULL, resulting in a double free if an error > occurs or later if hvfb_remove() is called. > > Fix this by removing all kfree(info->apertures) calls in hvfb_getmem(). > This will allow framebuffer_release() to free the memory, which follows > the pattern of other fbdev drivers. > > Modulo this revision to the commit message, which Wei Liu can > probably incorporate, > Yes. I surely can incorporate the changes. I will also add the Fixes tag. > Reviewed-by: Michael Kelley