Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2188672iof; Tue, 7 Jun 2022 22:37:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyF3Askdyyc6I7+8ath6XdZ6AvU87PcwiMozSiUHsdzoQTJHpLRNzafx7H7rjfm7JwiJ4Tk X-Received: by 2002:a17:90a:7e02:b0:1e0:a6a7:6eb with SMTP id i2-20020a17090a7e0200b001e0a6a706ebmr35690747pjl.203.1654666629633; Tue, 07 Jun 2022 22:37:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666629; cv=none; d=google.com; s=arc-20160816; b=vLNl+AdrtM7pcqZPnQ1rT6ICd42tKT+w9f9gOc0uxMu1USCcUVACmjX0zidHx5IDnh ZZZePbL0/sBfhBZsyBMEJxvvPmyJrH7rVFzyhfXW2sW41lolfJb0CyWUtYCW+EYV3Kni ZxCicDS5GlE4Weq24sgqQ8zSNg42Nib2VRBTZWLKMu2Zb8WvJq+fciuFX8sVJpebAf7v XuW9Mk641GoACHakbCvUGHv6ZvkzXQLgp6B0++sgVIP2KNpGgKhzvFqNHCFqMOsxgzum JJbpBpndu1zo/rbkIjLQpTg8gYcoaSWzAvLTn5P5D9YVkWttsUbv5HMVrPzDO/7wscM3 S4+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date; bh=4GgGZsNsjGs97ZiHIIcwU+oDFLshKL4PoxoDBkijcmA=; b=Vmg98nsp1a/fvjtyC5+KowR610wesfYx0hKce3+lf5mus5veQ3dsli1eRbYev6y/wn 9PcF1ItnPi2yux88mBbs2HyEoUoMNFzkdJLl7ElHLy2QUsZ3sMNG20KCpJQ62upqGYkY QDy1paKpbAAAmOSZCs+lE1wENoD9SonB3CvSrtHHZdAvP9oi+EsjvhoK6dhId9C/76hS D+2xtxNL1RcQhtCQ2Mxva+HgItRXmGydWuiwXDJkKNT40xeHm/FePrsYKTiSuvXZKKVx vM5A66TtIi+qxZDVJbCquaoVM8XDF5dxa3bXPr3U8YgdY7YOCOFEYXAJVcnW6WSzpcHZ vfig== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id cm18-20020a056a00339200b0051bc46f9672si23568494pfb.45.2022.06.07.22.37.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:37:09 -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; 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 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0383849F69F; Tue, 7 Jun 2022 22:13:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351840AbiFHAeB convert rfc822-to-8bit (ORCPT + 99 others); Tue, 7 Jun 2022 20:34:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445942AbiFGXEa (ORCPT ); Tue, 7 Jun 2022 19:04:30 -0400 Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDDF135D46C for ; Tue, 7 Jun 2022 13:23:56 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 7957D61B8B69; Tue, 7 Jun 2022 22:23:13 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 9QQEM-g-k7R7; Tue, 7 Jun 2022 22:23:12 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id D08F7608110A; Tue, 7 Jun 2022 22:23:12 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 7tquQMvYHDkA; Tue, 7 Jun 2022 22:23:12 +0200 (CEST) Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lithops.sigma-star.at (Postfix) with ESMTP id 9CD0D61B8B5A; Tue, 7 Jun 2022 22:23:12 +0200 (CEST) Date: Tue, 7 Jun 2022 22:23:12 +0200 (CEST) From: Richard Weinberger To: =?utf-8?B?TWljaGHFgiBLxJlwaWXFhA==?= Cc: Miquel Raynal , Vignesh Raghavendra , linux-mtd , linux-kernel Message-ID: <1710081060.147491.1654633392520.JavaMail.zimbra@nod.at> In-Reply-To: <20220516070601.11428-2-kernel@kempniu.pl> References: <20220516070601.11428-1-kernel@kempniu.pl> <20220516070601.11428-2-kernel@kempniu.pl> Subject: Re: [PATCH 1/2] mtdchar: prevent integer overflow in a safety check MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-Originating-IP: [195.201.40.130] X-Mailer: Zimbra 8.8.12_GA_3807 (ZimbraWebClient - FF97 (Linux)/8.8.12_GA_3809) Thread-Topic: mtdchar: prevent integer overflow in a safety check Thread-Index: JX134mBLLXSr5mg7slOI+t/fmFEWJA== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 ----- Ursprüngliche Mail ----- > Von: "Michał Kępień" > An: "Miquel Raynal" , "richard" , "Vignesh Raghavendra" > CC: "linux-mtd" , "linux-kernel" > Gesendet: Montag, 16. Mai 2022 09:06:00 > Betreff: [PATCH 1/2] mtdchar: prevent integer overflow in a safety check > Commit 6420ac0af95d ("mtdchar: prevent unbounded allocation in MEMWRITE > ioctl") added a safety check to mtdchar_write_ioctl() which attempts to > ensure that the write request sent by user space does not extend beyond > the MTD device's size. However, that check contains an addition of two > struct mtd_write_req fields, 'start' and 'len', both of which are u64 > variables. The result of that addition can overflow, allowing the > safety check to be bypassed. > > The arguably simplest fix - changing the data types of the relevant > struct mtd_write_req fields - is not feasible as it would break user > space. > > Fix by making mtdchar_write_ioctl() truncate the value provided by user > space in the 'len' field of struct mtd_write_req, so that only the lower > 32 bits of that field are used, preventing the overflow. > > While the 'ooblen' field of struct mtd_write_req is not currently used > in any similarly flawed safety check, also truncate it to 32 bits, for > consistency with the 'len' field and with other MTD routines handling > OOB data. > > Update include/uapi/mtd/mtd-abi.h accordingly. > > Suggested-by: Richard Weinberger > Signed-off-by: Michał Kępień > --- > drivers/mtd/mtdchar.c | 3 +++ > include/uapi/mtd/mtd-abi.h | 4 ++-- > 2 files changed, 5 insertions(+), 2 deletions(-) > > diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c > index d0f9c4b0285c..b2700f8467ff 100644 > --- a/drivers/mtd/mtdchar.c > +++ b/drivers/mtd/mtdchar.c > @@ -615,6 +615,9 @@ static int mtdchar_write_ioctl(struct mtd_info *mtd, > if (!usr_oob) > req.ooblen = 0; > > + req.len &= 0xffffffff; > + req.ooblen &= 0xffffffff; > + Yeah, I think it is reasonable to limit write requests to 4GiB. Thanks, //richard