From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EEF5190473 for ; Sat, 20 Jun 2026 13:05:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781960718; cv=none; b=BR5hR9VK6FlCA4KeOQ9nACzjybs5iKKJ279goosShEHdbnIx3tckC5hR+B/U7xxnrrQkZR7mUoeBKff4LFWYujmM2OvwCApaQK1dBJaBQ08B6Hx8cXTP9/nktPYECgnAjyWQgKvuG0RhD+mbRJH85D0Fp6W5z/vIS2NKipvA4UY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781960718; c=relaxed/simple; bh=q4EZ6OR4A5r+vYVW0WwAdAY3/xr45QE3znbsYFb4++c=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=rTZWc1hjeKBSEXtx370Y7r+3PE1eqgoN46tBQqiSG60pZVzlM8SVKgZ79cdaa9CyyNQ8cDRnVdISEo+g6df2xw2OFjdZNBqVBR6vimcNc1ZzVju897J6q4zjUCdzW0h4Eih8js/w6JHLzzY28XE38VLBFRJj9cFNk4dL4SQzX30= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.167.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-4867683976aso5212080b6e.0 for ; Sat, 20 Jun 2026 06:05:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781960716; x=1782565516; h=to:from:subject:message-id:in-reply-to:date:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DvwiZzMuY7MPZ2uGH4572JhZnDTY0mJFXRaBDkYIr4s=; b=mZcD22/3oqkeLP9T+qdQzjfEPn/aDjE/TzrCoFPFNY0i2ohYiLfKynLUVRHXIfe4lT XD4xq7iD9uCipLQ31ljlvE2p7vyXNUReRnyKQKXcCtWlQqC5HrSTSHV5/K7ODZ4OOIQ2 yWvd+8ej9pQlk3UHBKRJfuP6wqxYUZ+Yv9x/loF3fpP+5CipgdNNAvGpQEToBpz9kNeG 3wg70SgzVMQMSQbV7hcZcY+uaE6X4JaCR/C2wJ7tX7crZuMZ9YEVcLAZxli2/UG5RQXM CoYECVemSVzHoixjXFCMlDkdkuaEXS5C+Np4McR//9Qf381+vG0iS5IU3RiLBX2Bje+W wEhA== X-Gm-Message-State: AOJu0YzLQyq0gkf8bAXJG4YTFXrnlmk//gco2HzKl/myWSXtQCF7jy4H A2UOaB/v7Dn43N5w7p+DgVNM+pB0LGuqOF+81SGi0oRlm17Mhfz0wsKAstg+FS73jBFA0P+4I/X 5OIvNXrzq137lIObj3+08znS9TD4hpUPwLLi6+5wlWKLiuTcBD/Ki1IVNp1s= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6808:3c4f:b0:48a:e1f7:5ec5 with SMTP id 5614622812f47-48ae206a6b9mr2977427b6e.31.1781960716414; Sat, 20 Jun 2026 06:05:16 -0700 (PDT) Date: Sat, 20 Jun 2026 06:05:16 -0700 In-Reply-To: <6a364dbc.713c5d62.148f7.0000.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <6a36900c.956a836d.179a93.0000.GAE@google.com> Subject: Forwarded: [PATCH] mtd: mtdpart: validate partition bounds in mtd_add_partition() From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH] mtd: mtdpart: validate partition bounds in mtd_add_partition() Author: kartikey406@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master mtd_add_partition() checks that 'length' is positive but does not validate that 'offset + length' fits within the parent partition's size. A userspace caller using the BLKPG_ADD_PARTITION ioctl can supply a crafted large 'length' value that passes the length <= 0 check, causing add_mtd_device() to fire a WARN_ON() when it detects the oversized partition. Fix this by adding explicit bounds checks before allocate_partition() is called: - Reject negative or out-of-range offsets. - Use u64 arithmetic to safely check offset + length <= parent_size, avoiding potential signed integer overflow. Reported-by: syzbot+3ae80219c633aca5431c@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3ae80219c633aca5431c Signed-off-by: Deepanshu Kartikey --- drivers/mtd/mtdpart.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 795a94e6b482..1a0e2207e440 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -264,6 +264,11 @@ int mtd_add_partition(struct mtd_info *parent, const char *name, if (length <= 0) return -EINVAL; + if (offset < 0 || offset >= (long long)parent_size) + return -EINVAL; + + if ((u64)offset + (u64)length > parent_size) + return -EINVAL; memset(&part, 0, sizeof(part)); part.name = name; part.size = length; -- 2.43.0