Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp58517lfe; Fri, 15 Apr 2022 19:24:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwz144TV57GGeoQVhOG3bOAlCwKmjX1pvkL7jnjs7qYWubY+j456tuv9gFQGeRpPDf6hAjQ X-Received: by 2002:a63:4184:0:b0:39d:fbca:80fe with SMTP id o126-20020a634184000000b0039dfbca80femr1410661pga.153.1650075842029; Fri, 15 Apr 2022 19:24:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650075842; cv=none; d=google.com; s=arc-20160816; b=XdnInMdc4vxasGSZv7ARnskJvdFKZ4kmXkd8sid4OsgyWcQIDfwycK8dZsTNBLHtjS 0pF7Tovkl/7Ou185qeUgL3aWCHvvpw8dTHvBxlbMKLQfRmrw9zbimlNYhEKd0lPGCsOa 3hkZYhM2kAjp/3PsNjUwNahSpmvb5GgfBow1JPf870DACbrQJ6XzGAxre5FTaTdeDCoy fspCmM3M9syun5BsNVoEXHGplmo1/pjtedhKDODDM8Wpb1CC5idDUqUUebXnNvNFyfqc JnHcK0q9TFmKq3i1VXNQ2tOFmx4uybnd2unY1rcergXmYvBfC1Ybae5fVAJsdMgMRcTi O8ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=rAQUyFFCAm9hAIpMthk09aJ6bzB1j1wIgJVRYFh3f58=; b=JafKSukdRJtYUB0jcJY8aHaJeafYekSKpecnrPys1Py+RGGydbyMMRjegI/rzLuQZ9 pTJ8L4/Xb4KdoXYM63ZlR2cppJWapEcxk7yZ+V17rI/Nc/Z11q24VmDIqQ8PrHfIcyZF nYm3uZ+eGb9+3jSD85DsoNx6CJgQHZJ7VxfI31bWIuR3/l3le8c2mnENW8WfLphELFs0 nulnCfQjNipbnXc2JiA+fYtIbpHitRMwsVuJQjLVzQgVxD7Jn6cSPr63W+lGjMpVJtOd pJ1zJBtZVMxkMj1vCKMDB0D2CXsZGl9UwhGndyWW2F2muyzyxCv28VN6L83PhqOf0RpC 6YTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=E3GbblU9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id b7-20020a056a000a8700b004ffa29aaa7dsi2972784pfl.261.2022.04.15.19.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:24:02 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=E3GbblU9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E800415D3BB; Fri, 15 Apr 2022 18:36:19 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347100AbiDNWoG (ORCPT + 99 others); Thu, 14 Apr 2022 18:44:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239245AbiDNWoF (ORCPT ); Thu, 14 Apr 2022 18:44:05 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5D0E2A8 for ; Thu, 14 Apr 2022 15:41:39 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id a16-20020a056902057000b00641c83f82f5so5415494ybt.22 for ; Thu, 14 Apr 2022 15:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=rAQUyFFCAm9hAIpMthk09aJ6bzB1j1wIgJVRYFh3f58=; b=E3GbblU9eh7nB1JiPymsjFnwzoT6TbQMf8ldul6KS4xO2fQSx1uK7JVhfC4can/CSz 7V3LtWsBoV+qeu9UUPZaLqIeOXV5EyYsNzOkhQTey1XvrEyokJJ9QU5U+uLqMhdgZtbp p9yBKq2F+QtfzHyUFMsCjoo6rUMGGkcTpV3of2gXzgwOnyDUXdpqlzV03XFTgetPnHte hPHGZIlI+HqWxTTk19bBAEzEPP6x9R92M6n5jSuGU3sHRHY69QwA0MTCGQKiMFRPpuG2 Y8ARNaB2Czz6794TSC/U4ORN2ewJpmEP0d03K7ypNDwXgC455icI9HQupJDXoB9fThr6 9v7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=rAQUyFFCAm9hAIpMthk09aJ6bzB1j1wIgJVRYFh3f58=; b=WPKV/OAKlixGcC32gPI9zZeRo9n0eRIX1W2umntx8GawnnV6tIJwl6Sun2hp+Bq9K1 /mbmBbGTVpxmfwaPg7OnFAi3uF47JZangBh3gW3rI9/H2Fm7o+LdT9xMxr3zXBDvk991 8nllbGM8E7lKymMOXSGRq9RvOOI3AppR8FbSZBPIuH9KjEsFE7F5fvq7FstTm4AVwjg4 fy/zUHDvyhUooupTWktLHJsmDj+Fbiw7ddKTnDQQgzAqicX1BAPsEc07UsrlS8A5+KRe y4TBMlLftBYunTEogQ99vMYgkAPYuQOZbX8v7OZyjGeGZc3i99UoX3NOxlMVI1NuC6MC 5NPA== X-Gm-Message-State: AOAM5328yIPbu9uIbpzCKm4MwCFPb3re+A3uIvkAjc4xZucXZXMBs05k 1z3FtQwEkXM/41GQb9+MMS2YNNW4kkQ= X-Received: from khazhy-linux.svl.corp.google.com ([2620:15c:2cd:202:a4e5:c402:edee:ce9e]) (user=khazhy job=sendgmr) by 2002:a81:9ca:0:b0:2eb:f567:217f with SMTP id 193-20020a8109ca000000b002ebf567217fmr3782016ywj.322.1649976099028; Thu, 14 Apr 2022 15:41:39 -0700 (PDT) Date: Thu, 14 Apr 2022 15:40:56 -0700 In-Reply-To: <20220408234707.2562835-1-khazhy@google.com> Message-Id: <20220414224056.2875681-1-khazhy@google.com> Mime-Version: 1.0 References: <20220408234707.2562835-1-khazhy@google.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [PATCH v2] block/compat_ioctl: fix range check in BLKGETSIZE From: Khazhismel Kumykov To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Khazhismel Kumykov , Bart Van Assche Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 kernel ulong and compat_ulong_t may not be same width. Use type directly to eliminate mismatches. This would result in truncation rather than EFBIG for 32bit mode for large disks. Reviewed-by: Bart Van Assche Signed-off-by: Khazhismel Kumykov --- block/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) v2: addressed bart's comment diff --git a/block/ioctl.c b/block/ioctl.c index 4a86340133e4..f8703db99c73 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -629,7 +629,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) return compat_put_long(argp, (bdev->bd_disk->bdi->ra_pages * PAGE_SIZE) / 512); case BLKGETSIZE: - if (bdev_nr_sectors(bdev) > ~0UL) + if (bdev_nr_sectors(bdev) > ~(compat_ulong_t)0) return -EFBIG; return compat_put_ulong(argp, bdev_nr_sectors(bdev)); -- 2.36.0.rc0.470.gd361397f0d-goog