Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp670915pxk; Wed, 16 Sep 2020 14:00:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/d5UsDimOn5PifNFdcwVC6d/qakC355YSFpZHFxYHOUErkfE+UsghKEzcWKPv6EcSz/WW X-Received: by 2002:a17:906:abc5:: with SMTP id kq5mr26763265ejb.284.1600290009584; Wed, 16 Sep 2020 14:00:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600290009; cv=none; d=google.com; s=arc-20160816; b=vKenJGLgGLleO2Co+aDoUg1S2AZ2XJK1BgvqOb4uEJOgIBhS6TV7n1YErOf0OLs6ce sBxfMHsDF5pMTfEHlz9tSSMNnmmRO+eNlR0m4tAYa+fhPJVJmFWtQI5dtUAy07dLWyN6 cg3nK4GJYev9BRVn7Y9Euq4BHQZwuxGYdaEYsusQljiACtDlkCa90oPkq43gegzDTE1H +LOGmtRsvoFMIro24zTVbukfkD8MpSxfRzmjTwnuVRp845UBsAa4TnoWqUCNGsFWnOj+ mWHLtRlnysZX/WcTTbjQ23cv8TfO0voYksBuMHNiR/0bAtPVRvw8omEakcFKlgAXPmb4 EQ/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=krxdzrPQlPhb6qCigikuY4CsIZEbzfLzM7yHugdQpNU=; b=e8owMUJO4ViChCDxXcPGf7s2E2KANF2cLUWczpba7iU26OijwCCzMfCjPTv3V+vOCY OPzQIoF6czCQj1gGcBU7EoDU5ydKjKnKOslOF7JEurJcr3KzAzJ7McOGvmdau67JfFJA gIqnsNzAGia5sqgl0YInjQmlZdxFNc1MH715mhslyxQ+uswPa6ozXiNcuwlCbMCvp+Lx jN8oNnykG9nNECveQeuaGUFXZ3z7PUCwKTtFB7Wy39B8OuluLLE7sZjrUdu5mo5940Ab nMPtZ8B0S9eZ6SVjA1vuzTLKVdEb35cNfHQ4d4r0qJ+Zu09gRQNXxJ50HhwXxc97OeYg 4JHg== 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p16si12503676ejw.31.2020.09.16.13.59.46; Wed, 16 Sep 2020 14:00:09 -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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726584AbgIPU6i (ORCPT + 99 others); Wed, 16 Sep 2020 16:58:38 -0400 Received: from mga17.intel.com ([192.55.52.151]:8404 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726515AbgIPQbq (ORCPT ); Wed, 16 Sep 2020 12:31:46 -0400 IronPort-SDR: DP0SPWB6BtUVdPJ8EMrzDQu4tdcofjtkqugKFr0ptwGe/B6PgqchDl5foqzcor8FXY0pMGeLKz egTuHEesu2QA== X-IronPort-AV: E=McAfee;i="6000,8403,9746"; a="139498286" X-IronPort-AV: E=Sophos;i="5.76,433,1592895600"; d="scan'208";a="139498286" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Sep 2020 08:16:10 -0700 IronPort-SDR: uu2rgLYbGEv6J48JHwMxcBc511k4mgfP134TD7aU7UXlQzTz0M+Iv/9M61KM0JCqy+ben9akZ8 q7ZlZTEB55QA== X-IronPort-AV: E=Sophos;i="5.76,433,1592895600"; d="scan'208";a="483349223" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Sep 2020 08:16:10 -0700 Date: Wed, 16 Sep 2020 08:16:09 -0700 From: Ira Weiny To: Dan Carpenter Cc: Souptick Joarder , mporter@kernel.crashing.org, alex.bou9@gmail.com, akpm@linux-foundation.org, gustavoars@kernel.org, jhubbard@nvidia.com, madhuparnabhowmik10@gmail.com, linux-kernel@vger.kernel.org, Matthew Wilcox Subject: Re: [linux-next PATCH] rapidio: Fix error handling path Message-ID: <20200916151607.GB2485491@iweiny-DESK2.sc.intel.com> References: <1600227737-20785-1-git-send-email-jrdr.linux@gmail.com> <20200916100232.GF18329@kadam> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200916100232.GF18329@kadam> User-Agent: Mutt/1.11.1 (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 16, 2020 at 01:02:32PM +0300, Dan Carpenter wrote: > On Wed, Sep 16, 2020 at 09:12:17AM +0530, Souptick Joarder wrote: > > There is an error when pin_user_pages_fast() returns -ERRNO and > > inside error handling path driver end up calling unpin_user_pages() > > with -ERRNO which is not correct. > > > > This patch will fix the problem. > > There are a few ways we could prevent bug in the future. > > 1) This could have been caught with existing static analysis tools > which warn about when a value is set but not used. > > 2) I've created a Smatch check which warngs about: > > drivers/rapidio/devices/rio_mport_cdev.c:955 rio_dma_transfer() warn: unpinning negative pages 'nr_pages' > > I'll test it out tonight and see how well it works. I don't > immediately see any other bugs allthough Smatch doesn't like the code > in siw_umem_release(). It uses "min_t(int" which suggests that > negative pages are okay. > > int to_free = min_t(int, PAGES_PER_CHUNK, num_pages); > > 3) We could add a check in unpin_user_pages(). > > if (WARN_ON(IS_ERR_VALUE(npages))) > return; Does IS_ERR_VALUE() work on an unsigned variable? The issue with adding a check in unpin_user_pages() is that npages is unsigned long. Ira > > It's not possible to pin more than "ULONG_MAX - 4095" because otherwise > returning error pointers wouldn't work. So this check can't break > anything and it could prevent a crash. > > regards, > dan carpenter >