Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp2009162lqp; Tue, 16 Apr 2024 05:02:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVSsg3+LXCwkbB6Q+Y6ZXFJvuVovXN2a3WQofvy+klCySbFFE5SOwe0BEVt4eu1K0QAn8KnIqnEG7arK/R0EvZWfxgxzio+YHTBwvjOiQ== X-Google-Smtp-Source: AGHT+IFX1jEm5IXdz7i4NnfX7N9wTeiqvK+5BuCkS5AgcFXOrBNOaj5Toq01uJ5HBOeuhS2Ctl0p X-Received: by 2002:a17:90a:a589:b0:2a2:97f3:83b3 with SMTP id b9-20020a17090aa58900b002a297f383b3mr9694616pjq.48.1713268965170; Tue, 16 Apr 2024 05:02:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713268965; cv=pass; d=google.com; s=arc-20160816; b=qgzMznxLKaesBcW64ChEcok3yF6bsSkEpAHkjXPjx5htlvIF8VZec3ilKOdFxd+Km7 AzkLS930M+C0xsdx4NPP79Jioryk9wJUnj91qZqqfntqcRHUH5nbA9nVDVYx99koJ9Uc qf5iVYqGIHRHbnksQtiXzKvUKdU4yLG4gZAf1bOUHeC3Auc29lbE1W6t/MJRNz4Of9Y4 EQzJvlWRry19Ywb1bC6EUkLbg4iplv1GiMgweXMzKgjITSIxHbSOeK0K00xLYeHZoksf eRNpbJ8ujO67MiWzPzyJ82MQQehLt7+Ma3GTXb4euF5DU7QuTG5ojfPEQ4nMdAAq9Cq/ EfNQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=QIxLUAMbjgurxXoHq9EdG3sBEmu/NGzsdsQ94b87puk=; fh=befnN+cbIAUnNoLksGWH8qSI8UFlQb0+BL+QDsVAPWQ=; b=stFBMXwJnup8rLt9P4ixgX6cD4G1acLA6lRIJtMBvgLHe+nb0eFhe/snlopA0/+MOh mIV/eqbKwWdMckXZmA6KQtGFCrUutV9ZlcoagPacBoFlYNCfKtzk33xl9o98z/ALKhKe rqkhO5w/hTvvovo53mYb4IPY0wMbPIYGwxg1QKb43wNWBHD2GQQWLg/EemMigBCal7EG yeSsmZC3CXiaKMpurh8V4xnKlQGTQOcc0ms2tCzKvQnXcTSU+5fETsCZB9dX8D5EmMSJ T1k7dFwMVXTMMcEnBRlKH977NffrhFe/89sSvh3PCfS0v3ZqAlkpiq967krBKtUzhn0e lUEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mvrzWBhU; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-146736-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146736-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id w23-20020a17090a029700b002a24fd29f92si11914081pja.117.2024.04.16.05.02.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 05:02:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-146736-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mvrzWBhU; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-146736-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146736-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D1CDFB2221A for ; Tue, 16 Apr 2024 12:02:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3F82512A179; Tue, 16 Apr 2024 12:02:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mvrzWBhU" Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 B206F129E78; Tue, 16 Apr 2024 12:02:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713268945; cv=none; b=OkbW4+cnkP+c1Rhq8W7yMCGBCLQk+0fiBg+QxczpARr4MIHmGrUMHC2613jbQmnVymcG8yvidS3AOcEBBpTBFthJ9/UjVY5XxL7G8KNs5E/TwU1mR7iWEugUJn0kAWENcGorx8yhzkRTmDVsmMhTCZPQCCod7UyrfXqU/CH7//8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713268945; c=relaxed/simple; bh=mehokU/oPv9zSJz1ECT72XIz6TIwRXXiUhrnhSfTj5M=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=DsfYT2yuODAxIC7lW/PC4H3nehZ0/Skw128u962Vj/hawjm/mIl5/2gELmulmsE0uBt9tEJNm1hfRqzQC59v4Obco7/S9Vkm6G3LIeivMexMmjk98p1A+Kwy+nwDEFes5B1NLKHaOVu3hzTcmFwPcL8leNfx2vhrVNiY/V+VbMk= 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=mvrzWBhU; arc=none smtp.client-ip=209.85.218.54 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 Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a524ecaf215so361156866b.2; Tue, 16 Apr 2024 05:02:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713268942; x=1713873742; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=QIxLUAMbjgurxXoHq9EdG3sBEmu/NGzsdsQ94b87puk=; b=mvrzWBhUo9A9k76i9yZG+WtcVLVFI1iyQHDi0dn372xytKMVG/9wqc2fZVUBR8kYsu r9S9d24VYHYYHNssCKecYV3QI4FIu85YYFpFYaVUhtjBSah7AgfUA//v2Adon5oTYrOk P/F9PKfP51dxaptKO6qjdkA/dnQTZiF9ry/ce3AbWCj5OapEKFEmsJCto6cwqDmbeVhe dfWpxktBSXz2vh/NdlbCOyCXOElMUJlfE/W/xLnp/z6IZ9yt9zlJ2pn9hR6p1heeXFQU QV+8Cx6EgRaLHDut69T9Z6WIqXN3hIub4zJdBolzy5WF6aRO1Kz9elxr+jYqI8oTUBG2 IWrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713268942; x=1713873742; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QIxLUAMbjgurxXoHq9EdG3sBEmu/NGzsdsQ94b87puk=; b=egfsNxF/zxwl256gN7UzPZZNxRRhKEvO/L8ojA0+2pecGBiO6fYasXfBh1nneXdo6P hG6niyTkz5RCtKKoX4BPU1SNBjCGilFjvDct8HaPf+I/1YyKSJ0Y9xU0iDgNWI29UBHt itpJpUX4foZplNrwhp5QLCzwE/bKr1jSdoYDNVhZbOeGpEbQYBT1JNJTEAv3yZUbgZYq 35sBB/rNSFCgW1qsE4q0iYLHYOFhqgxaAVxt49he839yaLQFP6gw6B0WzHXlF0RxGDiw i3Igis4u7o9zOjakBvXhcWFZCaqnih8GZE3x8nJUOM7zVMcJi2ejzy43WJV/HpzORXwm x8OQ== X-Forwarded-Encrypted: i=1; AJvYcCWeGi4n1jE7QptQNMgkkihuTLfF2GBTnFc5B+iYnDEmsmKbOj8E9t3rqUVeOn8u4NsHdBdAjiEk+ar+JoLsn4C2j/hESqwH X-Gm-Message-State: AOJu0YyjOn8U8xbpG67B5YSjCJuIMzoJVhJaG0/SOW33dpzQlyo9mkNr GYBm1vkoYlQFa4+GrxHUYYdzZ1LnA8mpDn1MvsdLoyhW/78Udam+Y7407ROQVhmq16+9mipFF0B Zu0JHmtRKTmrXD3gAbFUo/GPwqWBI29/CmeI8apa0 X-Received: by 2002:a17:906:29cb:b0:a52:61b9:be48 with SMTP id y11-20020a17090629cb00b00a5261b9be48mr4119771eje.35.1713268941706; Tue, 16 Apr 2024 05:02:21 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: Sam Sun Date: Tue, 16 Apr 2024 20:02:10 +0800 Message-ID: Subject: Re: [PATCH net v2] drivers/net/bonding: Fix out-of-bounds read in bond_option_arp_ip_targets_set() To: Hangbin Liu Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, j.vosburgh@gmail.com, andy@greyhouse.net, davem@davemloft.net, Eric Dumazet , kuba@kernel.org, pabeni@redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 16, 2024 at 6:03=E2=80=AFPM Hangbin Liu = wrote: > > On Tue, Apr 16, 2024 at 03:28:02PM +0800, Sam Sun wrote: > > In function bond_option_arp_ip_targets_set(), if newval->string is an > > empty string, newval->string+1 will point to the byte after the > > string, causing an out-of-bound read. > > > > BUG: KASAN: slab-out-of-bounds in strlen+0x7d/0xa0 lib/string.c:418 > > Read of size 1 at addr ffff8881119c4781 by task syz-executor665/8107 > > CPU: 1 PID: 8107 Comm: syz-executor665 Not tainted 6.7.0-rc7 #1 > > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04= /01/2014 > > Call Trace: > > > > __dump_stack lib/dump_stack.c:88 [inline] > > dump_stack_lvl+0xd9/0x150 lib/dump_stack.c:106 > > print_address_description mm/kasan/report.c:364 [inline] > > print_report+0xc1/0x5e0 mm/kasan/report.c:475 > > kasan_report+0xbe/0xf0 mm/kasan/report.c:588 > > strlen+0x7d/0xa0 lib/string.c:418 > > __fortify_strlen include/linux/fortify-string.h:210 [inline] > > in4_pton+0xa3/0x3f0 net/core/utils.c:130 > > bond_option_arp_ip_targets_set+0xc2/0x910 > > drivers/net/bonding/bond_options.c:1201 > > __bond_opt_set+0x2a4/0x1030 drivers/net/bonding/bond_options.c:767 > > __bond_opt_set_notify+0x48/0x150 drivers/net/bonding/bond_options.c:79= 2 > > bond_opt_tryset_rtnl+0xda/0x160 drivers/net/bonding/bond_options.c:817 > > bonding_sysfs_store_option+0xa1/0x120 drivers/net/bonding/bond_sysfs.c= :156 > > dev_attr_store+0x54/0x80 drivers/base/core.c:2366 > > sysfs_kf_write+0x114/0x170 fs/sysfs/file.c:136 > > kernfs_fop_write_iter+0x337/0x500 fs/kernfs/file.c:334 > > call_write_iter include/linux/fs.h:2020 [inline] > > new_sync_write fs/read_write.c:491 [inline] > > vfs_write+0x96a/0xd80 fs/read_write.c:584 > > ksys_write+0x122/0x250 fs/read_write.c:637 > > do_syscall_x64 arch/x86/entry/common.c:52 [inline] > > do_syscall_64+0x40/0x110 arch/x86/entry/common.c:83 > > entry_SYSCALL_64_after_hwframe+0x63/0x6b > > ---[ end trace ]--- > > > > Fix it by adding a check of string length before using it. Remove > > target address in netdev_err message since target is not initialized > > in error path and will not provide useful information. > > > > Fixes: 4fb0ef585eb2 ("bonding: convert arp_ip_target to use the new opt= ion API") > > Signed-off-by: Yue Sun > > I think the fixes tag should be > > f9de11a16594 ("bonding: add ip checks when store ip target"). > Sorry for my mistake. I will change the fixes label to this commit. Best, Yue > Thanks > Hangbin > > > --- > > drivers/net/bonding/bond_options.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/net/bonding/bond_options.c > > b/drivers/net/bonding/bond_options.c > > index 4cdbc7e084f4..8f3fb91897b3 100644 > > --- a/drivers/net/bonding/bond_options.c > > +++ b/drivers/net/bonding/bond_options.c > > @@ -1214,9 +1214,9 @@ static int bond_option_arp_ip_targets_set(struct > > bonding *bond, > > __be32 target; > > > > if (newval->string) { > > - if (!in4_pton(newval->string+1, -1, (u8 *)&target, -1, NULL)) = { > > - netdev_err(bond->dev, "invalid ARP target %pI4 specified\n= ", > > - &target); > > + if (!(strlen(newval->string)) || > > + !in4_pton(newval->string + 1, -1, (u8 *)&target, -1, NULL)= ) { > > + netdev_err(bond->dev, "invalid ARP target I4 specified\n")= ; > > return ret; > > } > > if (newval->string[0] =3D=3D '+') > > -- > > 2.34.1