From patchwork Mon Oct 28 07:58:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 2003144 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XcQlc1Xgzz1xxY for ; Mon, 28 Oct 2024 18:59:39 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1t5Key-0005JK-6I; Mon, 28 Oct 2024 07:59:32 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1t5Kew-0005GY-LI for kernel-team@lists.ubuntu.com; Mon, 28 Oct 2024 07:59:30 +0000 Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 761E03F2A2 for ; Mon, 28 Oct 2024 07:59:30 +0000 (UTC) Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3e606c05b87so3553678b6e.2 for ; Mon, 28 Oct 2024 00:59:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730102369; x=1730707169; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0IPhtGnQMlLYiHZg4HICi6jCMC70ekL1ZTswxlhlQUI=; b=EI/Nsf2QAHQd9LI/QOh0e6D4pPHfdFapbMUsGv/DpsCzzLuY/hrDoXDTiWnuCr7pNg LTgfz52H5fPN9R6xElVnRHg2LEFLOr0V+JtZdQBDr6aO5ZX3BX+dLWx5cMS+a7xF7HZR XX2BsP4dro1DxuDrCkIoAHnAe2h2uI9pSfqmGHJtuNQ7K8o8+k9wNKY+vxfCMt5MeotZ 72AfKD6fKzsReQKYEB5wLDbdgjsRtZRzbNRVxyThaZIfdnQHsYWkZ5XexPei7283j6h+ PpOv0Y03v6suZJ5czBwqv9aiBF8PZ0ybar8yGrPO7LgdXqLBZDV3S04BWd3+42AO08lh aiUA== X-Gm-Message-State: AOJu0YxXs2ZUDXu6+nRDo8mtPhAvnx2zcqGQtwWnQP/J2qA9+f7kxjlL HMGYqSoBvxFPcvOv/mmToK0o+76CKOrN9Dx+pHlOprsK+SRb8wHmH84gHcACEwZNxN9Wgdeqa7d UV9LOTpvSRF4TxjNhnSk+h52yMvvHx7S+w7sftV2EreGJLwibhecc8/Pw+vgbf83vpvKdTLjeR8 Yw+IY32OVTew== X-Received: by 2002:a05:6808:219f:b0:3e6:16f7:9742 with SMTP id 5614622812f47-3e63848e130mr4906319b6e.33.1730102369197; Mon, 28 Oct 2024 00:59:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOmOoNFBYeuNvVlsY5PUrW3Y3qZ9n5LZETeutkaFd2GdX8ygMwGvvpMSeeiyzBhHxr1FX6aw== X-Received: by 2002:a05:6808:219f:b0:3e6:16f7:9742 with SMTP id 5614622812f47-3e63848e130mr4906304b6e.33.1730102368863; Mon, 28 Oct 2024 00:59:28 -0700 (PDT) Received: from localhost.localdomain ([240f:74:7be:1:fc2f:5f77:13cb:653f]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc89f595dsm5127262a12.59.2024.10.28.00.59.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 00:59:28 -0700 (PDT) From: Koichiro Den To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 2/4] Bluetooth: RFCOMM: Fix not validating setsockopt user input Date: Mon, 28 Oct 2024 16:58:53 +0900 Message-ID: <20241028075902.114546-3-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241028075902.114546-1-koichiro.den@canonical.com> References: <20241028075902.114546-1-koichiro.den@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Luiz Augusto von Dentz [ Upstream commit a97de7bff13b1cc825c1b1344eaed8d6c2d3e695 ] syzbot reported rfcomm_sock_setsockopt_old() is copying data without checking user input length. 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 rfcomm_sock_setsockopt_old net/bluetooth/rfcomm/sock.c:632 [inline] BUG: KASAN: slab-out-of-bounds in rfcomm_sock_setsockopt+0x893/0xa70 net/bluetooth/rfcomm/sock.c:673 Read of size 4 at addr ffff8880209a8bc3 by task syz-executor632/5064 Fixes: 9f2c8a03fbb3 ("Bluetooth: Replace RFCOMM link mode with security level") Fixes: bb23c0ab8246 ("Bluetooth: Add support for deferring RFCOMM connection setup") Reported-by: syzbot Signed-off-by: Eric Dumazet Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin (cherry picked from commit eea40d33bf936a5c7fb03c190e61e0cfee00e872 linux-6.1.y) CVE-2024-35966 Signed-off-by: Koichiro Den --- net/bluetooth/rfcomm/sock.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c index 4397e14ff560..c9bd5c7d6260 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c @@ -636,7 +636,7 @@ static int rfcomm_sock_setsockopt_old(struct socket *sock, int optname, switch (optname) { case RFCOMM_LM: - if (copy_from_sockptr(&opt, optval, sizeof(u32))) { + if (bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen)) { err = -EFAULT; break; } @@ -671,7 +671,6 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, struct sock *sk = sock->sk; struct bt_security sec; int err = 0; - size_t len; u32 opt; BT_DBG("sk %p", sk); @@ -693,11 +692,9 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, sec.level = BT_SECURITY_LOW; - len = min_t(unsigned int, sizeof(sec), optlen); - if (copy_from_sockptr(&sec, optval, len)) { - err = -EFAULT; + err = bt_copy_from_sockptr(&sec, sizeof(sec), optval, optlen); + if (err) break; - } if (sec.level > BT_SECURITY_HIGH) { err = -EINVAL; @@ -713,10 +710,9 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, break; } - if (copy_from_sockptr(&opt, optval, sizeof(u32))) { - err = -EFAULT; + err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen); + if (err) break; - } if (opt) set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);