From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 3BDE827A12F for ; Sat, 20 Jun 2026 17:06:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781975200; cv=none; b=JHY9w7OtWosWvNyI47OoFjvyRm2B0XiaS0/TUinKheUXnK/QyvY3YfYBOBv1HE2AGtIM3G3Kmn4bCjTkNG+GP4onZzxuYEEhIp82Id09+oRIA90Rx02EYLw2jzXGohmS/ia8T1hAEzECzV7RRSVG4+xO7v88nPubqLRNVX8nYic= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781975200; c=relaxed/simple; bh=WTm1zq48U1gm/+xm9O/LdA8nMfEWJBIqq64xtJ7KNi0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=PdQufPMn5E13Ndod0w9iOkCTLbgAOAbLRN66AiqWSCsNdvn8nzaIeB8QB67EIMeSai5ALTQOi9pOUGj0VqNmCyxGDgKhtuHor+wVAOF70+o4so52QxUnyajNsCcmHVtrnCwfsXdszJRt/TevuswjMpiWY7OJTF3RjMuP/dmxNn8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nCRDNHt3; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nCRDNHt3" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-3967701fc3cso5750071fa.0 for ; Sat, 20 Jun 2026 10:06:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781975196; x=1782579996; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8iEduaZP3uRIog+A+9jyhhzskmnge2cwf7E3YRjfZ34=; b=nCRDNHt3CU80PwxNEqf2Jl0LLTmt0CA/CT+DPrOHefqqIvD/CcoDyCaOibh7ETRgd/ RLry7e0ptOGAtazTnbxDHzY2fYuJGFQ0B2nbe5aSG+nTu3sN6fRXRolr/iiPJK3eRHoj Ltur7vARB/tbemLRAsFo7Z+5caZixxVLBHiTAXbvWvQxHKk8HJbWkIGtn4AfMrn9vWUv V/58ZnQSxNpMBfK/fUXmhqRpPUVo2A72P+LtJYBWIA3eGONVmpxdoFV1ODoCMNJAbXya bxHsPsJ2vQldmRrmUPSTyYcEhAVqay2JHcsALazbHpZXrAh7sjBWD3DquIuJjQgF9lM8 0N8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781975196; x=1782579996; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8iEduaZP3uRIog+A+9jyhhzskmnge2cwf7E3YRjfZ34=; b=JoVS/1E4MPscYk9rxaLlkB+XTbLHzpIYDwmjMZ7ZyezfDvTDvZNlnQwKpe5p+/tuaX /AHXH9Um2EYMtuEMmJB2NndTEEVzgahTRkqJlPcM7DAHB3uY+SWs6mH1Xkq1uPN+DTyE Kb0ISNE8keggSibPXqJ0Xoi+K4Ll95VLf8p2Ff8m7aIz24Tuiz9l6y4pj/G3pMw2Fp3X JpqPPtGagQ/ihgZuQMVGZwzHgaTi0npxFX9N3pDWQC3V4fXUOD1t1bF/uaqhS62uRIgN cR2SZdj4PVYi4E2q5QPf9IvoMqlU/koy6cyMYmD3tFVLIRc9n4fFqjsuvKJPApTXXG+b J1GQ== X-Forwarded-Encrypted: i=1; AFNElJ+aR0MXrOKs4JWpPHvBBSAl0EnQ7GmOrgyfmCyVG/XAopI/KCEDKD+wWHiPSdpLBRgVkB2TXNVPqFIYeo0=@vger.kernel.org X-Gm-Message-State: AOJu0YzMVowGq9CMcLucwTuTsyZD+WRvJdaxBxjYHwQ77iuNePz1FH5Q l9anmOWfY1ogmrCxDWsLUVe78vyxEhQYjxHgZn5f0vj81WjPw7rfibXuVwx31OK+923Elg== X-Gm-Gg: AfdE7cmZ/Xwyod9yrjf3moLhIEl3lDX5zTH901VCWD9bnNQiARBJfYXBcxXwiT6oJs/ KvlNBZ1FUlwhxsLb3O1nHXg7UhALzGKdfy5bGyLqhbul9lHXnVmPex6GiXTVfCqKk3opYNqfIra 3fYIuuJIfEhlfAeW3qb2P8Zn4ixwIXKW73ZJpy+7NzUMDoy514N+tCK72PTEJO1FmXw4wf9rk28 Z/sTwesV99WlJedMTVQLBn7sNvk2Ay9gpe+2eOEm04sbClnzsejtZlpq/fZsUKQsLgN+dnrbqSR +C7AEExBP/f97nW1dF1n936aI+zJn+CAkulEcMf4tzLSFb6818HtvzmZU4RBJybTCL4o0eBqkpc QZ6Yl2LHYceV0C2RcN90Ltwo5L7IhwYsGjTe3hUWH3umsW1mmgXjRj42HnUUDYZHs1Onh6TCoUW jJk2amz5daz8oHoKOarF2oCd5LpkekTNno X-Received: by 2002:a05:6512:a95:b0:5ad:4c8e:6941 with SMTP id 2adb3069b0e04-5ad5624d140mr1380136e87.0.1781975196247; Sat, 20 Jun 2026 10:06:36 -0700 (PDT) Received: from localhost.localdomain ([195.211.194.218]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5ad5c2aed03sm600535e87.42.2026.06.20.10.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jun 2026 10:06:34 -0700 (PDT) From: Nikolay Ivchenko To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, syzbot+3ae80219c633aca5431c@syzkaller.appspotmail.com, Nikolay Ivchenko Subject: [PATCH] mtd: mtdpart: fix uninitialized erasesize on MTDPART_OFS_RETAIN error path Date: Sat, 20 Jun 2026 20:06:03 +0300 Message-ID: <20260620170603.334732-1-nivchenko.dev@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When parsing partition layouts, if a partition requested with MTDPART_OFS_RETAIN runs out of space, the allocator jumps directly to 'out_register' to preserve partition numbering. However, this jump bypasses child->erasesize initialization, leaving it at zero. When add_mtd_device() is later called on this child, the registration fails and triggers a WARN_ON() due to the zero ->erasesize. Fix this by zeroing out child->part.offset and child->part.size, and initializing child->erasesize to parent->erasesize. This is the exact same pattern already used just a few lines below in the "out of reach" error check (child->part.offset >= parent_size) to safely register a disabled partition. Reported-by: syzbot+3ae80219c633aca5431c@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3ae80219c633aca5431c Signed-off-by: Nikolay Ivchenko --- drivers/mtd/mtdpart.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 795a94e6b482..7f23f8a1b59c 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -118,6 +118,9 @@ static struct mtd_info *allocate_partition(struct mtd_info *parent, part->name, parent_size - child->part.offset, child->part.size); /* register to preserve ordering */ + child->part.offset = 0; + child->part.size = 0; + child->erasesize = parent->erasesize; goto out_register; } } -- 2.43.0