Received: by 10.192.165.148 with SMTP id m20csp71814imm; Fri, 4 May 2018 06:54:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrCYYrIR2CEwRCn1wNKMZ1EMKK4qmKxFlIaRZArbRNaNtcLvHSbt2CbIF9RSYXMT2gQ6Q4E X-Received: by 10.98.159.202 with SMTP id v71mr26993102pfk.233.1525442089792; Fri, 04 May 2018 06:54:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525442089; cv=none; d=google.com; s=arc-20160816; b=xcmM4SPNC4OVy0Q4FIKEBYHtaUGb8J1I9ERc+lOs73p53xjLZmKZjCjQlaKIQKKSis RgN2aHPI/pK8SLYGzJiTCcXFKgQpCQAw9B8R1AkIQJHbVcM6oaTSsHsnIkT3T8Krztzc vzkJPmcWQtDMfB5KlI0cCGqxJZ4+sGoSUqq2CYDPksdaFZ4BSQc1VPEvj6lWC4HZX4XJ H1BxWi/0OpKT9sS+RzYFXUCspronEf1RmKhFED7b3NgAV0qnIhrttcgNQoAAiNUXJR3i XV8oMQLtdwBCcq3aLtGIQF+VaXLsIBissYbJQxJ2o7Trcay1M8X1SAnq2qPfPNQ2RoP7 Ytgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:date:cc:to:from:subject :message-id:arc-authentication-results; bh=OAPTbQgkIu47yjJZxeWO/MUM2GrC/zAP5lPWviHNbUo=; b=mcdo8TeYuhskXjl5iUnxPFADyXi40JxLa1V2OfSPmxowU+7jnjLOFb7hv9usFYVV8O cIhuJFuJHOHxmZwyAxkx5iE5cMfv0tZX4tw7k9jE63QcXWJ/34b3LdhAJayzkUjqgiWo aCPyngUq0I8SOEOeFF7weexNdFTLuPlol6kyiY6KBTDnr/zfob9KvZ1/X6LJaNdLbcRm Zv9sbqLVBXR3Qpch8D4bi+2D8JmZmGwB1udVdjdnwUfUiOVhzJMX28CXWi9mx9Yri0Mw 6Sp2poz0zqfiD6nvLYT2vcr2ge1VmeTTJ0WK+6SVRptztignCDSJSjQHNvso8rZSoQeO LrUw== 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 x1si15485839pfm.32.2018.05.04.06.54.35; Fri, 04 May 2018 06:54:49 -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 S1751903AbeEDNyL (ORCPT + 99 others); Fri, 4 May 2018 09:54:11 -0400 Received: from mga11.intel.com ([192.55.52.93]:34162 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751562AbeEDNyC (ORCPT ); Fri, 4 May 2018 09:54:02 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 May 2018 06:54:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,362,1520924400"; d="scan'208";a="38432497" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.86]) by orsmga007.jf.intel.com with ESMTP; 04 May 2018 06:53:58 -0700 Message-ID: <1525442037.21176.659.camel@linux.intel.com> Subject: Re: [PATCH] media: staging: atomisp: fix a potential missing-check bug From: Andy Shevchenko To: Wenwen Wang Cc: Kangjie Lu , Alan Cox , Sakari Ailus , Mauro Carvalho Chehab , Greg Kroah-Hartman , Hans Verkuil , "open list:STAGING - ATOMISP DRIVER" , "open list:STAGING SUBSYSTEM" , open list Date: Fri, 04 May 2018 16:53:57 +0300 In-Reply-To: <1525418996-19246-1-git-send-email-wang6495@umn.edu> References: <1525418996-19246-1-git-send-email-wang6495@umn.edu> Organization: Intel Finland Oy Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.5-1+b1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2018-05-04 at 02:29 -0500, Wenwen Wang wrote: > At the end of atomisp_subdev_set_selection(), the function > atomisp_subdev_get_rect() is invoked to get the pointer to v4l2_rect. > Since > this function may return a NULL pointer, it is firstly invoked to > check > the returned pointer. If the returned pointer is not NULL, then the > function is invoked again to obtain the pointer and the memory content > at the location of the returned pointer is copied to the memory > location of > r. In most cases, the pointers returned by the two invocations are > same. > However, given that the pointer returned by the function > atomisp_subdev_get_rect() is not a constant, it is possible that the > two > invocations return two different pointers. For example, another thread > may > race to modify the related pointers during the two invocations. In > that > case, even if the first returned pointer is not null, the second > returned > pointer might be null, which will cause issues such as null pointer > dereference. > > This patch saves the pointer returned by the first invocation and > removes > the second invocation. If the returned pointer is not NULL, the memory > content is copied according to the original code. > The driver will be gone soon, don't bother with it anymore. Thanks! > Signed-off-by: Wenwen Wang > --- > drivers/staging/media/atomisp/pci/atomisp2/atomisp_subdev.c | 6 ++++- > - > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git > a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_subdev.c > b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_subdev.c > index 49a9973..d5fa513 100644 > --- a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_subdev.c > +++ b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_subdev.c > @@ -366,6 +366,7 @@ int atomisp_subdev_set_selection(struct > v4l2_subdev *sd, > unsigned int i; > unsigned int padding_w = pad_w; > unsigned int padding_h = pad_h; > + struct v4l2_rect *p; > > stream_id = atomisp_source_pad_to_stream_id(isp_sd, > vdev_pad); > > @@ -536,9 +537,10 @@ int atomisp_subdev_set_selection(struct > v4l2_subdev *sd, > ffmt[pad]->height = comp[pad]->height; > } > > - if (!atomisp_subdev_get_rect(sd, cfg, which, pad, target)) > + p = atomisp_subdev_get_rect(sd, cfg, which, pad, target); > + if (!p) > return -EINVAL; > - *r = *atomisp_subdev_get_rect(sd, cfg, which, pad, target); > + *r = *p; > > dev_dbg(isp->dev, "sel actual: l %d t %d w %d h %d\n", > r->left, r->top, r->width, r->height); -- Andy Shevchenko Intel Finland Oy