From patchwork Fri Jul 14 18:29:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 13314160 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDBF8C001DE for ; Fri, 14 Jul 2023 18:29:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E34816B0071; Fri, 14 Jul 2023 14:29:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE4EE6B0072; Fri, 14 Jul 2023 14:29:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CAC766B0074; Fri, 14 Jul 2023 14:29:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BC5D66B0071 for ; Fri, 14 Jul 2023 14:29:44 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 63B4440365 for ; Fri, 14 Jul 2023 18:29:44 +0000 (UTC) X-FDA: 81011055888.26.FCA6911 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf04.hostedemail.com (Postfix) with ESMTP id 717484001F for ; Fri, 14 Jul 2023 18:29:42 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=mRXoMTCm; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3FZSxZA0KCDAMjQXdMeYgeeQZSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--axelrasmussen.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3FZSxZA0KCDAMjQXdMeYgeeQZSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--axelrasmussen.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689359382; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=yxAUfh9tXsKn2HpY20y1qdPrUCx+3NBgZb4IkMtE0Gs=; b=DbCT8ZjKoWq20kw3fgswsEBf6nLCSFzsdGC1NYkkVYe6xnMN3+ko3yoy+7ZfwBCCmkscve hOibAuStthJTuJFz7klnPrNgqR3H/zRmC8JcvNBEopPOKuIp/9n068L0cVgHaoeTXnn7ea ABAjFAFtYmir5m2MTiUWq8WHm5VlX7U= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=mRXoMTCm; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3FZSxZA0KCDAMjQXdMeYgeeQZSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--axelrasmussen.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3FZSxZA0KCDAMjQXdMeYgeeQZSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--axelrasmussen.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689359382; a=rsa-sha256; cv=none; b=QIpsPlc+8xoDiPK6ANtK5hf/wEfsSvRvKix9eFj06onECPGKEAhSyQLZw3HqRqaKyXSXjo lu3i5djszPzndja3DFgcsRBTvWiFyvOJeXBNcIKFdLy61e64TTBlPjVfigiClU+mlKAMeu UNkd2oBCq+y+UhWBW3UEb37UIII3XdI= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-c4f27858e4eso1824925276.1 for ; Fri, 14 Jul 2023 11:29:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689359381; x=1691951381; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=yxAUfh9tXsKn2HpY20y1qdPrUCx+3NBgZb4IkMtE0Gs=; b=mRXoMTCmgDEUqGGQOSIsn5uuIWxzrKXnwuch52uQZkXJzVeF5h7KiOw042B2VG4MjP Ud668hnCaHqrAsJelWng9Y2s3bZEVDGgCwmtA+RKaeDYCfKMRATcF36o9bwXZSjLJXmD xGwtxtYrORJWP/GtvcdJ6DB3nWNbNp1NNsvwoy5dkJJkXV1mjG4ZyIAPBxa0ZeJy47wC lRAwtwRfLuaZHPN6fZIxopQbbbLZSH+r7pelwbYbHYvr6TN2ykZ5n8m7RT6Rx1PDAv41 itfOO1Y5wnapfiZ17WHQSzoXlIaDEkigdLEJ+n13E7rjAc5bMhn9nmE0OvXONw09Gqtv LCkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689359381; x=1691951381; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yxAUfh9tXsKn2HpY20y1qdPrUCx+3NBgZb4IkMtE0Gs=; b=RQ/Nzd57cSH/SLejote7VGc/49qAAFqGMmajKVkhKQ5hq8VGSZhhuuaYtT/Z3hWagw 0Y4hGwQd0f4TOBPtGEBsQ0G/1dXILcgF8h+ZMjkVcUzYoyH+o5H2xq+WNqqYozK2is8H VeJjlcEdJGQUd2VhqjVAYVxJ+3RojaUIa8kqLB6K5WwQheNnu1JEO5Vj0FceBEbX1yMi LP7h1nCHZCDV8GF8HEKIMq/Dwuz84sGff31QINlMN7FwMAtMQv3Plb3H8EZ8gn7sD6qf FMWpmHRyXy+NHFG/Rlupea/aNZqPA48rxVnWwHC+j81WQiSUcVWvDoaMznYn7bXMqWZs wQkA== X-Gm-Message-State: ABy/qLZmHXfUZRiu84WYYTL2H+u7zSenZhfaZnNU11+B8a4H7bbC4zbW TaToAL4JTF3715ki/ndLwS1vVc3cOjsbUlQgEyEI X-Google-Smtp-Source: APBJJlHJ/kyB4gtYJRA2tBe4+IdzDMyqED2Fs1IG5ccfZHYtkPxqRy1tdgRGDnnyoyPph5LKlnKkyWQ84gNPe3dqgbnb X-Received: from axel.svl.corp.google.com ([2620:15c:2a3:200:eeac:4e26:b121:5ef2]) (user=axelrasmussen job=sendgmr) by 2002:a25:4157:0:b0:c10:8d28:d3ae with SMTP id o84-20020a254157000000b00c108d28d3aemr26174yba.8.1689359381331; Fri, 14 Jul 2023 11:29:41 -0700 (PDT) Date: Fri, 14 Jul 2023 11:29:32 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230714182932.2608735-1-axelrasmussen@google.com> Subject: [PATCH mm-unstable fix] mm: userfaultfd: check for start + len overflow in validate_range: fix From: Axel Rasmussen To: Alexander Viro , Andrew Morton , Brian Geffon , Christian Brauner , David Hildenbrand , Gaosheng Cui , Huang Ying , Hugh Dickins , James Houghton , Jiaqi Yan , Jonathan Corbet , Kefeng Wang , "Liam R. Howlett" , Miaohe Lin , Mike Kravetz , "Mike Rapoport (IBM)" , Muchun Song , Nadav Amit , Naoya Horiguchi , Peter Xu , Shuah Khan , Steven Barrett , Suleiman Souhlal , Suren Baghdasaryan , "T.J. Alumbaugh" , Yu Zhao , ZhangPeng Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Axel Rasmussen , syzbot+42309678e0bc7b32f8e9@syzkaller.appspotmail.com X-Rspamd-Queue-Id: 717484001F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: xnsezea89z41d9nopg1duqupbjcjehxy X-HE-Tag: 1689359382-994540 X-HE-Meta: U2FsdGVkX1+oDM2n1VFR037I779ttfiZTkYMqQbZf8RmMGwufxbuXnUrVCFPgDI48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z2STxTTXACg3NqawHywvpfqjxe2VeWyucq2zw8fyhC37PLPI7Jl27jHqR4SeckxSn6ZtAj/SNju3iPgET1paObH0GhqiWynvXfuK2ft+wWP2YPgCJFxETPD8zycMYyd9IENeIh0pMk9Vxc/Uu/K2bAe3FhDF2gVjcWqtzEextsuUCaLcF6O3k0baLkmW6d6aUrS1u5Zq5WLTW9pCgDfQzn49Fr9fysFXWKG42/B3+6MRARPmqkwwMTzkcAiC1ABa316Ocmtpb/3Dmts9cGG+YbMiat9wPr1+31r04dHbrzH/LDzCnEQ9LPpF/0IYRY6NPOn9uLjAdHqlSAJLE0IXLRx1+4m67kcrqddCE8w3FI4Y1jpFTTO0/81adKFcCO3oF3NixgLLX1R0pXbLlH5F2ulvvKrORtwFCDREGTsrX5w7dLIc8AMpQcprLogOt3GTy9OmlFIOCCgaAYDEyqlzuctNLQX5qRN231GXxJxgEFpdt/XCBskXgdLO9v19kXiNtEpasg5MfkeduDCXPlkV0RojcKZ6uFcgRXVmRRUOUdRyGYBV6xXHgY87GbToDjM3ZC37+sHqU0lIdKxB7wluV0XrDwRK4XC45BqdDY5eJZRMdD2qkC8MwYoF7lQ8arpVdIXyAO2dL71VOYT1tFxbWZu+BYbAHiUQDpzLxV+qoFo+hQD9HIJwOUjvWdMKW2re2mksLa4PXw8RMUuhPIVQ5H3XY8UU/tIGkvB5/2xsb/oRBTMtW+v0pB2I/NlM/ggy41Hv6CJ+2o8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This commit removed an extra check for zero-length ranges, and folded it into the common validate_range() helper used by all UFFD ioctls. It failed to notice though that UFFDIO_COPY *only* called validate_range on the dst range, not the src range. So removing this check actually let us proceed with zero-length source ranges, eventually hitting a BUG further down in the call stack. The correct fix seems clear: call validate_range() on the src range too. Other ioctls are not affected by this, as they only have one range, not two (src + dst). Reported-by: syzbot+42309678e0bc7b32f8e9@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=42309678e0bc7b32f8e9 Signed-off-by: Axel Rasmussen --- fs/userfaultfd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 53a7220c4679..36d233759233 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1759,6 +1759,9 @@ static int userfaultfd_copy(struct userfaultfd_ctx *ctx, sizeof(uffdio_copy)-sizeof(__s64))) goto out; + ret = validate_range(ctx->mm, uffdio_copy.src, uffdio_copy.len); + if (ret) + goto out; ret = validate_range(ctx->mm, uffdio_copy.dst, uffdio_copy.len); if (ret) goto out;