From patchwork Sat Dec 9 10:05:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyunwoo Kim X-Patchwork-Id: 13485998 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=theori.io header.i=@theori.io header.b="Oe9dcVWc" Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B15091703 for ; Sat, 9 Dec 2023 02:05:43 -0800 (PST) Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-1f055438492so2018501fac.3 for ; Sat, 09 Dec 2023 02:05:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=theori.io; s=google; t=1702116343; x=1702721143; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=s5PCTRTJRZnHK1MRbANCAmJkU16b0mVctmay1KaTY14=; b=Oe9dcVWcGt38FFugG/p/rM+T2epgZb+dJRdQT9xt2VuSDCDLvIU9VqMWtIk1beFZUo WDWbJt+KSid8TNEpnSYt1cRLr3H+0gSQMweiKN0yzCzzeR6I/WIZZYer9sQYDQU0ROq0 r9N+hyL9aIXJFc4QbNI7k32C0HEByOb4ZWV3w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702116343; x=1702721143; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=s5PCTRTJRZnHK1MRbANCAmJkU16b0mVctmay1KaTY14=; b=NhecGSL4wTU773ywsAAvq27qATM+Lh5E7bHhb5cM2rF9IqwzNcGstKtz+evVvv0BiD VqE4p9uXcUq1IyybQoqpU3Xk4TH5nw3Q4riYz7fJRmqE9rA5+svwwOR0t+xgA4j+4DOZ 6iqvBmMdyDGsFuah/XFCRPaQqsOilgRECdjvgJrTp8genPr6QiqokoavSUS0rkFn83rD HgOXItYQ5yH5VXMu2RBYiWc8rD5250t9csd6H69mqZCaHso7v0E+1cilj0A1M3JyoPcB LfktJuFCyG1TjlnyqwLcQHaQD/krR0qF88uxW1nmDfD7xh6QvOuNimmMjlxWBDVVvP0w moOQ== X-Gm-Message-State: AOJu0YyYgqTkvLNzYXBm026PDM/9mbnJL22+dLQB9Sc7OFU4U88jYy8G vQuUXAqf62b6wkPaYyU7rGjNLw== X-Google-Smtp-Source: AGHT+IFqUTfK53OGgVUo3hyrpGjNPYDkuoBGZ7aTIyivGMBPwZwtRUuRlEC6XuuIsvCmvt2qXtNnvA== X-Received: by 2002:a05:6870:d18c:b0:1fb:2bec:9fb5 with SMTP id a12-20020a056870d18c00b001fb2bec9fb5mr2088274oac.0.1702116343074; Sat, 09 Dec 2023 02:05:43 -0800 (PST) Received: from v4bel-B760M-AORUS-ELITE-AX ([211.219.71.65]) by smtp.gmail.com with ESMTPSA id 17-20020aa79111000000b006ce6c661701sm2642953pfh.139.2023.12.09.02.05.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Dec 2023 02:05:42 -0800 (PST) Date: Sat, 9 Dec 2023 05:05:38 -0500 From: Hyunwoo Kim To: ralf@linux-mips.org, edumazet@google.com Cc: v4bel@theori.io, imv4bel@gmail.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, linux-hams@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4] net/rose: Fix Use-After-Free in rose_ioctl Message-ID: <20231209100538.GA407321@v4bel-B760M-AORUS-ELITE-AX> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-Patchwork-Delegate: kuba@kernel.org Because rose_ioctl() accesses sk->sk_receive_queue without holding a sk->sk_receive_queue.lock, it can cause a race with rose_accept(). A use-after-free for skb occurs with the following flow. ``` rose_ioctl() -> skb_peek() rose_accept() -> skb_dequeue() -> kfree_skb() ``` Add sk->sk_receive_queue.lock to rose_ioctl() to fix this issue. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Hyunwoo Kim --- v1 -> v2: Use sk->sk_receive_queue.lock instead of lock_sock. v2 -> v3: Change spin_lock to spin_lock_irq v3 -> v4: Delete old comments --- net/rose/af_rose.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c index 0cc5a4e19900..ecb91ad4ce63 100644 --- a/net/rose/af_rose.c +++ b/net/rose/af_rose.c @@ -1315,9 +1315,11 @@ static int rose_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) case TIOCINQ: { struct sk_buff *skb; long amount = 0L; - /* These two are safe on a single CPU system as only user tasks fiddle here */ + + spin_lock_irq(&sk->sk_receive_queue.lock); if ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) amount = skb->len; + spin_unlock_irq(&sk->sk_receive_queue.lock); return put_user(amount, (unsigned int __user *) argp); }