From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34B3CC43334 for ; Wed, 6 Jul 2022 16:18:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234367AbiGFQSX (ORCPT ); Wed, 6 Jul 2022 12:18:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233659AbiGFQSQ (ORCPT ); Wed, 6 Jul 2022 12:18:16 -0400 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B09227FE2 for ; Wed, 6 Jul 2022 09:18:15 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id h19so18925722qtp.6 for ; Wed, 06 Jul 2022 09:18:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Z5AtWZPe7XoqBJU6Mk4sFJpC18BYt1O5VeJ13XcQzX4=; b=Ewz99xqh8v2JGDRnfSIbSELjNOHHdsxNwR3glx8EoOGGev5aohpcw6bWI/kSKPXG0P eN6PsAah0mHTRNi3bHI/PD93M4mNRFT9xFR7Xp1ALIJ7MO5UqM1gbfU0vtFnJL4eAXBj 7HrxdcAznMe+kLEOERuVkQ9iw6gfkPre8defoP11IpiTfUbN7erJSe1v4uTtXgHQMNYK qNiR89H3qjJgEivlIv3cciUWJwZPYmnvfH/tVJ18bh+iMtLrA+MY48Ku6YwKjZlJHlyQ gsVePEmk9eXsyuDLBOad6mIO/zu+2ZipibQZ/do77BtbkNy7IWxAJErql/N1oRbG6ebq Ozqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Z5AtWZPe7XoqBJU6Mk4sFJpC18BYt1O5VeJ13XcQzX4=; b=EdU4yXLmFwqtzzOeNEwj+lP3yTcRcRRUptEwSOah4gCJS6QZaF5FhgrI0ysqR6fBCW XR0PaQTXBXe5MjkQjKt/3RfDdtROIix5WFSAX5akOmO9WmJbHEuIXfi43KcYrHqJnEdO TCJtrJAY7LYM21IQQQ+1pUC8NnDP/kucmMR+KD6xD1EzsHr0bFa5yd52Z8+GbwBKX6gM KyLr+2swAWw4CdSm6svfTCbRGyFVKT/gMytc205gs0MZo4D3Vq7hJ6sqVEV4rjUFI1J/ p/asRHiTOHVi+m9eFbBX26+mbsVuIkmKjVPXAwcQGssz17SYcVQ2dmC/qCC3OdtFFtoq fZDg== X-Gm-Message-State: AJIora9CLu8DKxVRuyMXppl9kM4Lay5I01HUOv9QE+ZPFPQBhX1KCrfC 9+2FG1TeXELl+mT3z64PdNyRhQ== X-Google-Smtp-Source: AGRyM1uj3Zv5IfAsAH88CBXvJ1B+xqPgTHtuEYaKAMVSg+irD6dNO967VZRHDnXBhdHxHFqYCJ6SLg== X-Received: by 2002:a05:622a:450:b0:31d:3a5d:fc50 with SMTP id o16-20020a05622a045000b0031d3a5dfc50mr22010953qtx.433.1657124294361; Wed, 06 Jul 2022 09:18:14 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-162-113-129.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.129]) by smtp.gmail.com with ESMTPSA id v18-20020a05620a441200b006a701d8a43bsm24578677qkp.79.2022.07.06.09.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 09:18:13 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1o97jA-0076he-VG; Wed, 06 Jul 2022 13:18:12 -0300 Date: Wed, 6 Jul 2022 13:18:12 -0300 From: Jason Gunthorpe To: Dan Carpenter Cc: Longfang Liu , Yishai Hadas , Shameer Kolothum , Kevin Tian , Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH] vfio: hisi_acc_vfio_pci: fix integer overflow check in hisi_acc_vf_resume_write() Message-ID: <20220706161812.GJ23621@ziepe.ca> References: <20220705180649.GI23621@ziepe.ca> <20220706055124.GA2338@kadam> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220706055124.GA2338@kadam> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 06, 2022 at 08:51:24AM +0300, Dan Carpenter wrote: > On Tue, Jul 05, 2022 at 03:06:49PM -0300, Jason Gunthorpe wrote: > > On Tue, Jul 05, 2022 at 12:05:28PM +0300, Dan Carpenter wrote: > > > The casting on this makes the integer overflow check slightly wrong. > > > "len" is an unsigned long. "*pos" and "requested_length" are signed > > > long longs. Imagine "len" is ULONG_MAX and "*pos" is 2. > > > "ULONG_MAX + 2 = 1". > > > > I wonder if this can happen, len is a kernel controlled value bounded > > by a memory allocation.. > > > > Oh. Smatch uses a model which says that all read/writes come from > vfs_write(). The problem with tracking kernel read/writes is that > recursion is tricky. So Smatch just deletes those from the DB. Oh, maybe I got it wrong, len is the user input, so yes that does look bad > > This code was copy and pasted from drivers/vfio/pci/mlx5/main.c, so it > > should be fixed too > > Sure. > > I created a static checker warning for this type of thing but it didn't > catch the issue in drivers/vfio/pci/mlx5/main.c because Smatch says that > the bug is impossible. Which is true. How come it is different? Jason