Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2667629imw; Wed, 6 Jul 2022 09:42:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sBSMpwhZHK891DFCv99+gfDJlT02/M6a3lCwgMOc2VkNk9nmJQpv1kpCARjFYRYteLEdyq X-Received: by 2002:a17:907:1dc2:b0:72a:efdb:2c4a with SMTP id og2-20020a1709071dc200b0072aefdb2c4amr7328512ejc.25.1657125727408; Wed, 06 Jul 2022 09:42:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657125727; cv=none; d=google.com; s=arc-20160816; b=E/4AmV4Y10obm7lIBAHmIJHb5/F0djGsaoa5VEueECPWAxFItA9cmgxV5vQl3W5Lop 1FHpPvDTGy+rRi0WMpue0qbejPQGMemL67XCoxWhCUYGs7TykiPq5jyFp4pKbYy8YKh8 VRtKkBIwnjraJ7FEaHuDjZxeh7bh0byTwIQcTtlLooIE6lsBBEl9tuujYY4yM3bTgjrq vAeXEyfw4wuBwirZ7CeMmF/ebSlZuaAKEoHym7krBGzEaPe8QTM8pepDWj7Ibt6pvZnc sYW58U9sjNUE4hQ0DvJNiuEYMtiU6ELbZU7Hzrc+75RQr9ORGtS1ZMsE6zMMAVdNbtE1 orIQ== 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:dkim-signature; bh=Z5AtWZPe7XoqBJU6Mk4sFJpC18BYt1O5VeJ13XcQzX4=; b=CdmRNh9qrWWqq4T802hyWlIq1hiNBFLaLjUaK0Fkw2FM1hIuouuIoe9AFZd89wxPtc Kv4P28a/5bWk3/TSkoAWCw9BsR/LXWHVHvEyjf1AEX0Lcq4T4HoY5zbaxea6/O5p+0Y+ mKImY0dwc8oTOrSuuLbMCQwQ4IlyS3tg/f0G5Q68bqfhJmECIKFtMoBjeJvGjG+7589D VGCpl7iKaIFQ8jRg18D9LcBFZSMr2b1VSjpQ6kGK5pjfZLlKHjPD8roY8/h2ZXlCLZ2K VUSFpqyuCfsz1Lstvo48HCJ2aagafjjzTStNKcesMY4W4cUJaCLNdAr2M0BFsqCEi21s nUqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=Ewz99xqh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sb13-20020a1709076d8d00b00726e142a88esi3852623ejc.983.2022.07.06.09.41.41; Wed, 06 Jul 2022 09:42:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=Ewz99xqh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233207AbiGFQST (ORCPT + 99 others); Wed, 6 Jul 2022 12:18:19 -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-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> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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