From patchwork Mon Apr 8 08:28:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13620769 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 4991E37714 for ; Mon, 8 Apr 2024 08:28:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712564931; cv=none; b=pB5d21cgsaWi9hOOCG53n5nPtpdDYbF7CP3WVfUqqeqKkYBsmYUWCb+I1t5ItaShTHZfTkxLnNiInvBBuItKdpuAOgrbl9ZdSgnwRQft9r2w9/+s0k4gVtiA7X55h3fdaHsssgMrUPFaXacNVWiFko1bFeR9+oOW6ZXIZgz/S0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712564931; c=relaxed/simple; bh=Ogx6x8wEzFRYWl2JCGZob2NQ54bGTwQk0xC3KpFu2N4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=X2h0HdjODsgSl+LlYqesLBdVHpwwmkoW14vyrZEqG0RfXtJBKO7UwJfrcGKJEStAX0u3eswkkB6Ccsm4XjtwplXCtEX4H6G+1UywSW8wIIDuMk8QWQQc/VaQRTkxlag+kaIwoBJLo5xzav9c5NWNdMWO+iMirkgMRohElSzVsiU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=BHd/+uFT; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BHd/+uFT" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dbf618042daso6578102276.0 for ; Mon, 08 Apr 2024 01:28:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712564929; x=1713169729; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Eqf4RlGCPpFy6RShn6WYXNtP8jJeVY7I/inYXSrvjho=; b=BHd/+uFTp2TAGsVcU6i2OOP7DZAT6mjGVqAX4lnfR+twvFk3eZWMKZjrYtFOiQZh7D cIm/O6DY/45/kgJeOxFaW6HS9oO66yZ6X0sZQesL8PER35fDh3SXwSf/9T/u00lo1N8H ByC0gqR/QAe0+itdnuZ/LWJpbvLTiJMzykQILz6uTF/mtv7MGiMR8/60Xx+dnGlVHF0C h4HuvDVRIKpoE2XYgFgaRWs7uYgJuDUM4JBH0RB/+/U1ztQ8rX5VbFWcSWjzRb5kG4Yq nHrEEClnc7DBmRLamUrpoDnsgsNFj6GKiJj8/lsPVVLY3PO/3OLm1f9kmvI+P4x7aUCd 1iSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712564929; x=1713169729; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Eqf4RlGCPpFy6RShn6WYXNtP8jJeVY7I/inYXSrvjho=; b=edtfXb5tUCju/68aDeSa/uSQQ3h4RcuknauZBEYut7plq0OQIBA/9w2cI33myJ5Jqq xVk9JDFMlYe2b5TOXJYsvUODH/utNw8EvFGn8vkMtp38jQjyPkX588FzrE1C6/06KeVe C186OhJZbCfTP9fjtEZwPpBUZbcYq98pWF+o8H+mYeTAxJDJrwlTx9ZvidG5DsdPIJAV 3sQJcZW0O/xJ/WSgaChZpVjAN2RuLm+3o4sJk1aHUPM4sfXRsRl5vJ8NKMZu5JxeIWKV is8MkoTFz5UTCIRjpmF5o25lOdJ5YuiAodiN+8U8oomOJHppDqesV7fJzXIY5K4cJH0p oWVA== X-Forwarded-Encrypted: i=1; AJvYcCUy/2BA2fqjVvVhWMY+rQS3OrkvC4/QCBad/BmMsYzEx4s0tG6ze603/VBHUxw6waVkyaWhKb3gFENqZQ976O+sMMJL6CCj X-Gm-Message-State: AOJu0Yx1AaZouBiSm6ClxLuIDk2y0RwKwR7ze+1/8NeqeIFA4IeKxdKa 5c5uCvE5+h8QNTVlmo+mX/BLZrh6a3vEdc+Qlj1rFjl1IKEuJ7ghJSrvqzuHt32Z4+FgoKRGw/w R4RmAbY76rg== X-Google-Smtp-Source: AGHT+IE00yu6Nvif3YMTdsYdtDgowDLKhP5gCwhld7NaV1ISRN6ILkT3UuHX6US4r3NLC2leAYYWo0eMf7xoEQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:aca4:0:b0:dcc:94b7:a7a3 with SMTP id x36-20020a25aca4000000b00dcc94b7a7a3mr654445ybi.12.1712564929122; Mon, 08 Apr 2024 01:28:49 -0700 (PDT) Date: Mon, 8 Apr 2024 08:28:43 +0000 In-Reply-To: <20240408082845.3957374-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240408082845.3957374-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408082845.3957374-2-edumazet@google.com> Subject: [PATCH net 1/3] net: add copy_safe_from_sockptr() helper From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Simon Horman , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org copy_from_sockptr() helper is unsafe, unless callers did the prior check against user provided optlen. Too many callers get this wrong, lets add a helper to fix them and avoid future copy/paste bugs. Instead of : if (optlen < sizeof(opt)) { err = -EINVAL; break; } if (copy_from_sockptr(&opt, optval, sizeof(opt)) { err = -EFAULT; break; } Use : err = copy_safe_from_sockptr(&opt, sizeof(opt), optval, optlen); if (err) break; Signed-off-by: Eric Dumazet --- include/linux/sockptr.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/linux/sockptr.h b/include/linux/sockptr.h index 307961b41541a620023ad40d3178d47b94768126..b272d6866c87d837e340ce9e78e8fb3423efbddf 100644 --- a/include/linux/sockptr.h +++ b/include/linux/sockptr.h @@ -50,11 +50,36 @@ static inline int copy_from_sockptr_offset(void *dst, sockptr_t src, return 0; } +/* Deprecated. + * This is unsafe, unless caller checked user provided optlen. + * Prefer copy_safe_from_sockptr() instead. + */ static inline int copy_from_sockptr(void *dst, sockptr_t src, size_t size) { return copy_from_sockptr_offset(dst, src, 0, size); } +/** + * copy_safe_from_sockptr: copy a struct from sockptr + * @dst: Destination address, in kernel space. This buffer must be @ksize + * bytes long. + * @ksize: Size of @dst struct. + * @optval: Source address. (in user or kernel space) + * @optlen: Size of @optval data. + * + * Returns + * * -EINVAL: @optlen < @ksize + * * -EFAULT: access to userspace failed. + * * 0 : @ksize bytes were copied + */ +static inline int copy_safe_from_sockptr(void *dst, size_t ksize, + sockptr_t optval, unsigned int optlen) +{ + if (optlen < ksize) + return -EINVAL; + return copy_from_sockptr(dst, optval, ksize); +} + static inline int copy_struct_from_sockptr(void *dst, size_t ksize, sockptr_t src, size_t usize) { From patchwork Mon Apr 8 08:28:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13620770 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 AE75836AF2 for ; Mon, 8 Apr 2024 08:28:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712564933; cv=none; b=Nb264rUSMxxLcKgjI1IIDaSRNdnUEYzfe8AX85ZujCBIRUQG9djts9NlVIpgomsJ1Ku/zWRRU612e4i83Q+Pg5pZRr6MF6+C4y65dgIDH+hPbp41Iyro5963mO+wkkHCPwaiAlGk6LpJdh7wkEos/hfiAc2hdmQp2ePfBhnPIuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712564933; c=relaxed/simple; bh=ILGfKfl8I6bt2H+au9AhsuuyCKaG6RIMwE+K4jkIHsY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pMnihIKLM6xytoiSkeH80Qkm6+cHteYEmElzegjpUeCCPPfFb6y9pO/4L8C5fGMaXD18zemBA4BbQcNiH2wFGJkoxrcC/2qouSfl3+sXj7/pywKQ/H7benzCStgmN3065YGt3GBceUuoycXeBrwxpT03+xno/b3freveJkYYKEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=INXm6yRd; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="INXm6yRd" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b26ce0bbso7808294276.1 for ; Mon, 08 Apr 2024 01:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712564930; x=1713169730; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yybjFMAN71rn0WkyuXs2LQiLrbziHyRQJsoAUX+BZR4=; b=INXm6yRdxqhnHJY49lykMNMS/LZT7An1NREDpL3HrKpdLZt25bqEndgLqR5Z7WepiL 2p8gMeRn2X+iNECtPsicCmxZ8aGnELSiKQtnjLPvPf2kaWubvN8WE8V/G7Dp225oMQB2 yGWOdcD/aFZPmp3cePIwwbypy0p1F2bo8BmUuH9bAME+CX+PNkt4tA/8Q9tDPBH+r3pZ MnIoB0o9wAjdDyM45ErHiMH/mRa5AZH/D9oBtI4Ln1MJGgk+nfgp8rD0MKM2vxu+T9ob T2cR9NWn7vgKB73LftMjirCwegHCPwqtre8u6boLPb/OkD+6jPWIea+DbPeCq1czXM5v dq5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712564930; x=1713169730; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yybjFMAN71rn0WkyuXs2LQiLrbziHyRQJsoAUX+BZR4=; b=uaPwheTF73TWEypbQa/m54B6jK/bBJu3ZnUzGw/5Upahn9IDrFxn9XfRzqJAdmBrPu ljh0soY4h5D7NX9OvtA/h1WEEfUMRzFKdX5KwfL+K9dEm+yOF5CDQG82BZeQLti41qBM uc4KKLF+sgjUC4zTsdu7nKCPXjZe1PpsOeaxjqWnz427HXxhmAxvkdZHoroqFKAOgun7 u8WonLRuycBfSp+bYQ/PEnwMbfUV7u55dyXQDrYI+QHNVVIavtYx4xwQUWPqweDV87g8 8glGs9nycYwi81tbo+ouX4+CoWXN5Cq67K53OVk/YMPhckRGTXif3DQIpeNmMbvs32wb raWA== X-Forwarded-Encrypted: i=1; AJvYcCXlhRkT3vojj7RP0btqdFuXcafVLfdKsvV1glrJr9dxzQ917+uBP5PmalBM1u1i6UQSFHrQp1w40Obr58eRkwzKj7UHEakb X-Gm-Message-State: AOJu0Yz+VdE2O15l5YL3xIGVvm1zP4DVw4nP7bfJz9mgNJEubn2wC+cC YoXuudPYQ1ggolh9Zuxu0DNEHmEoHIwq1Z8otCdkQwdDrq7QmRuXbs9hnNH/lEpC7x6gbFa8mfa ii8ANWI4rog== X-Google-Smtp-Source: AGHT+IH+nmW4hfu4dSCWJOlGIue1gBz4IU9sKAbaw24npTmj3VStaAH5eIiCgIKUe6WnjWaM/Ohg7kaRXqJDvw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:18c1:b0:dcc:c57c:8873 with SMTP id ck1-20020a05690218c100b00dccc57c8873mr2497688ybb.9.1712564930735; Mon, 08 Apr 2024 01:28:50 -0700 (PDT) Date: Mon, 8 Apr 2024 08:28:44 +0000 In-Reply-To: <20240408082845.3957374-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240408082845.3957374-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408082845.3957374-3-edumazet@google.com> Subject: [PATCH net 2/3] mISDN: fix MISDN_TIME_STAMP handling From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Simon Horman , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet , syzbot , Karsten Keil X-Patchwork-Delegate: kuba@kernel.org syzbot reports one unsafe call to copy_from_sockptr() [1] Use copy_safe_from_sockptr() instead. [1] BUG: KASAN: slab-out-of-bounds in copy_from_sockptr_offset include/linux/sockptr.h:49 [inline] BUG: KASAN: slab-out-of-bounds in copy_from_sockptr include/linux/sockptr.h:55 [inline] BUG: KASAN: slab-out-of-bounds in data_sock_setsockopt+0x46c/0x4cc drivers/isdn/mISDN/socket.c:417 Read of size 4 at addr ffff0000c6d54083 by task syz-executor406/6167 CPU: 1 PID: 6167 Comm: syz-executor406 Not tainted 6.8.0-rc7-syzkaller-g707081b61156 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024 Call trace: dump_backtrace+0x1b8/0x1e4 arch/arm64/kernel/stacktrace.c:291 show_stack+0x2c/0x3c arch/arm64/kernel/stacktrace.c:298 __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xd0/0x124 lib/dump_stack.c:106 print_address_description mm/kasan/report.c:377 [inline] print_report+0x178/0x518 mm/kasan/report.c:488 kasan_report+0xd8/0x138 mm/kasan/report.c:601 __asan_report_load_n_noabort+0x1c/0x28 mm/kasan/report_generic.c:391 copy_from_sockptr_offset include/linux/sockptr.h:49 [inline] copy_from_sockptr include/linux/sockptr.h:55 [inline] data_sock_setsockopt+0x46c/0x4cc drivers/isdn/mISDN/socket.c:417 do_sock_setsockopt+0x2a0/0x4e0 net/socket.c:2311 __sys_setsockopt+0x128/0x1a8 net/socket.c:2334 __do_sys_setsockopt net/socket.c:2343 [inline] __se_sys_setsockopt net/socket.c:2340 [inline] __arm64_sys_setsockopt+0xb8/0xd4 net/socket.c:2340 __invoke_syscall arch/arm64/kernel/syscall.c:34 [inline] invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:48 el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:133 do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:152 el0_svc+0x54/0x168 arch/arm64/kernel/entry-common.c:712 el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730 el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598 Fixes: 1b2b03f8e514 ("Add mISDN core files") Signed-off-by: Eric Dumazet Reported-by: syzbot Cc: Karsten Keil --- drivers/isdn/mISDN/socket.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c index 2776ca5fc33f39019062b3d9fb8f02547a5e4139..b215b28cad7b76a5764bda8021cece74ec5cd40f 100644 --- a/drivers/isdn/mISDN/socket.c +++ b/drivers/isdn/mISDN/socket.c @@ -401,23 +401,23 @@ data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) } static int data_sock_setsockopt(struct socket *sock, int level, int optname, - sockptr_t optval, unsigned int len) + sockptr_t optval, unsigned int optlen) { struct sock *sk = sock->sk; int err = 0, opt = 0; if (*debug & DEBUG_SOCKET) printk(KERN_DEBUG "%s(%p, %d, %x, optval, %d)\n", __func__, sock, - level, optname, len); + level, optname, optlen); lock_sock(sk); switch (optname) { case MISDN_TIME_STAMP: - if (copy_from_sockptr(&opt, optval, sizeof(int))) { - err = -EFAULT; + err = copy_safe_from_sockptr(&opt, sizeof(opt), + optval, optlen); + if (err) break; - } if (opt) _pms(sk)->cmask |= MISDN_TIME_STAMP; From patchwork Mon Apr 8 08:28:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13620771 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 20DA0381BB for ; Mon, 8 Apr 2024 08:28:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712564934; cv=none; b=aqVJJugi2giulxjYi+kU4UelnPHxdi5OX7rSji6fo5OG45/GGM7Ln5CJjXfTKcCKqQgrxYwXPoAhC6tC/fNvHtzpW+cJ5m1DgKquf3qOFa9qzSDeeafFbe7tc9DmhVSS5HBsuGOdTvXZSSdEvutppMp7+7mQX8F60Ut/bvR7kLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712564934; c=relaxed/simple; bh=MYqlv9D40H40f13UIjC7zHoLDwM0tMcccHa/6DwQS1I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VquS9OhW0Dxiqhv5v2XnTQOWDPyGbb/LOG6LHxZf/1j5e38vSPuwoeUArk1xMTnhrDEbtTeOcbybifeiZKWP1w+kP4eHqdKMV+YXnf/1f9KXxc5y+28bp0oRbeM8c6bbCbaHAIvaQomK+AYWt9qx8xFnv6LRAP52MhihXAJ637w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Mb891Tlf; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Mb891Tlf" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61814249649so6514587b3.3 for ; Mon, 08 Apr 2024 01:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712564932; x=1713169732; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jsgjVYS5+lt6E4DMR+pupChoDCeq4tx4ij2d6OvD65U=; b=Mb891TlfHIeKipw7Y0XUy1ywq/oRGig6o22nIdAr0eePzv8yrir5h7PO8l27/n2uVg NkYPUnoxtjjj5oRhljnmQbqGmsyomh4sCR70fzYzSwqgJUAPFOTLuu0GOFelg8MkySCk rwEcDcTbvRdLl5V0q6YolHGkMv7RlcAAFndcXx1vIurNbtQExa/PYC71MgMOeiD9pTxv vG4aX19B3VqswUN1J2IRfJy+KsTIyO8NG9nVwY46nJR4aFLkOrbpItRt/k3xKi0DUOPT EY0iV635ifiWQwOgPjR/9Ngh5Dqr7keVPgVBDJiNFC0Boim+O/8xk3MexDdbVi0RXatT ONzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712564932; x=1713169732; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jsgjVYS5+lt6E4DMR+pupChoDCeq4tx4ij2d6OvD65U=; b=jo6HVjttMFXj5v4W0Ca/b//zFm5liNQkcgCCAJ9ZvpfT/slDVtWBVGxqKm7y9j7blt DSV3MTX96sEmoMg0YwwKAhbWhHOJZe9H07gBUdB2JlzeOozcqlovbAIF8AHuW1AFt7yM f7t3UwL5tRjTLIm/x8TLHm2GITrXywb5RnuzEP3vdyABtxFX+yQ+1LGDgk46gicVCIYI J34rzikmlnRg6KMNAnlql9YNi0UHcQa3ZApSqWsoOZUaGl+20k6iNRqx7sJsDMBki5+I E0Z7i39NF+7ltIEQQ/vcd10Hbvi9bb2wjPWddDCwSzPIzhBoBP6jzSmHptQGDqgBfI/2 LdpA== X-Forwarded-Encrypted: i=1; AJvYcCUXjW7LFJQ3zc4fzp5i5luijkkEbx2rl0/rUM1GB5T+/yWlYB3kzq+qWh4iF5pc9wsqSLp+4Dkgbu9I86ksVt422vyKZmcC X-Gm-Message-State: AOJu0Ywc+eaI1xmcuM6I87drIl1v+0zYtaRznrMsWjYHWWzo7dM6Y3UT 9QFHeh/EzTnXbvkMblx/HUwFZZiS9zOUyB74aufQ4QnHV5qRaXZUybwxMSstJCqkWth0YXdOA9n L3SHCFJVc/A== X-Google-Smtp-Source: AGHT+IHqZBDQM0gMzggv+1JmYNlJhuzPTb0GeD+FJ1Ms5i/xIesAAiv2KHG5Z+tj07/kW9K6qi/TtONkJMIHMw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:84c4:0:b0:617:cbc7:26f9 with SMTP id u187-20020a8184c4000000b00617cbc726f9mr1955066ywf.10.1712564932164; Mon, 08 Apr 2024 01:28:52 -0700 (PDT) Date: Mon, 8 Apr 2024 08:28:45 +0000 In-Reply-To: <20240408082845.3957374-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240408082845.3957374-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408082845.3957374-4-edumazet@google.com> Subject: [PATCH net 3/3] nfc: llcp: fix nfc_llcp_setsockopt() unsafe copies From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Simon Horman , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet , syzbot , Krzysztof Kozlowski X-Patchwork-Delegate: kuba@kernel.org syzbot reported unsafe calls to copy_from_sockptr() [1] Use copy_safe_from_sockptr() instead. [1] BUG: KASAN: slab-out-of-bounds in copy_from_sockptr_offset include/linux/sockptr.h:49 [inline] BUG: KASAN: slab-out-of-bounds in copy_from_sockptr include/linux/sockptr.h:55 [inline] BUG: KASAN: slab-out-of-bounds in nfc_llcp_setsockopt+0x6c2/0x850 net/nfc/llcp_sock.c:255 Read of size 4 at addr ffff88801caa1ec3 by task syz-executor459/5078 CPU: 0 PID: 5078 Comm: syz-executor459 Not tainted 6.8.0-syzkaller-08951-gfe46a7dd189e #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024 Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x241/0x360 lib/dump_stack.c:114 print_address_description mm/kasan/report.c:377 [inline] print_report+0x169/0x550 mm/kasan/report.c:488 kasan_report+0x143/0x180 mm/kasan/report.c:601 copy_from_sockptr_offset include/linux/sockptr.h:49 [inline] copy_from_sockptr include/linux/sockptr.h:55 [inline] nfc_llcp_setsockopt+0x6c2/0x850 net/nfc/llcp_sock.c:255 do_sock_setsockopt+0x3b1/0x720 net/socket.c:2311 __sys_setsockopt+0x1ae/0x250 net/socket.c:2334 __do_sys_setsockopt net/socket.c:2343 [inline] __se_sys_setsockopt net/socket.c:2340 [inline] __x64_sys_setsockopt+0xb5/0xd0 net/socket.c:2340 do_syscall_64+0xfd/0x240 entry_SYSCALL_64_after_hwframe+0x6d/0x75 RIP: 0033:0x7f7fac07fd89 Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 91 18 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fff660eb788 EFLAGS: 00000246 ORIG_RAX: 0000000000000036 RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007f7fac07fd89 RDX: 0000000000000000 RSI: 0000000000000118 RDI: 0000000000000004 RBP: 0000000000000000 R08: 0000000000000002 R09: 0000000000000000 R10: 0000000020000a80 R11: 0000000000000246 R12: 0000000000000000 R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 Signed-off-by: Eric Dumazet Reported-by: syzbot Cc: Krzysztof Kozlowski Reviewed-by: Krzysztof Kozlowski --- net/nfc/llcp_sock.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index 819157bbb5a2c6ef775633931721490b747f2fc8..d5344563e525c9bc436d5ad0b84380f0bcae62a8 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -252,10 +252,10 @@ static int nfc_llcp_setsockopt(struct socket *sock, int level, int optname, break; } - if (copy_from_sockptr(&opt, optval, sizeof(u32))) { - err = -EFAULT; + err = copy_safe_from_sockptr(&opt, sizeof(opt), + optval, optlen); + if (err) break; - } if (opt > LLCP_MAX_RW) { err = -EINVAL; @@ -274,10 +274,10 @@ static int nfc_llcp_setsockopt(struct socket *sock, int level, int optname, break; } - if (copy_from_sockptr(&opt, optval, sizeof(u32))) { - err = -EFAULT; + err = copy_safe_from_sockptr(&opt, sizeof(opt), + optval, optlen); + if (err) break; - } if (opt > LLCP_MAX_MIUX) { err = -EINVAL;