af_unix: Fix MSG_OOB bugs and prepare deprecation.
Subsystems (3)
cover af_unix: Fix MSG_OOB bugs and prepare deprecation.
Currently, OOB data can be read without MSG_OOB accidentally in two cases.
This series fixes 2 bugs, switch the default of CONFIG_AF_UNIX_OOB to n, and add warning to deprecate MSG_OOB support in the near future.
The last patch can be dropped if not needed.
Kuniyuki Iwashima (3):
af_unix: Call manage_oob() for every skb in
unix_stream_read_generic().
af_unix: Don't peek OOB data without MSG_OOB.
af_unix: Prepare MSG_OOB deprecation.
net/unix/Kconfig | 4 ++-- net/unix/af_unix.c | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)
Signature · 1 line
2.30.2
PATCH 1/3 af_unix: Call manage_oob() for every skb in unix_stream_read_generic().
When we call recv() for AF_UNIX socket, we first peek one skb and calls manage_oob() to check if the skb is sent with MSG_OOB.
However, when we fetch the next (and the following) skb, manage_oob() is not called now, leading a wrong behaviour.
Let's say a socket send()s "hello" with MSG_OOB and the peer tries to recv() 5 bytes with MSG_PEEK. Here, we should get only "hell" without 'o', but actually not:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
from socket import *
c1, c2 =socketpair(AF_UNIX, SOCK_STREAM)c1.send(b'hello', MSG_OOB)
5
Quoted 1 line
Quoted 1 line
Quoted 1 line
c2.recv(5, MSG_PEEK)
b'hello'
The first skb fills 4 bytes, and the next skb is peeked but not properly checked by manage_oob().
Let's move up the again label to call manage_oob() for evry skb.
With this patch:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
from socket import *
c1, c2 =socketpair(AF_UNIX, SOCK_STREAM)c1.send(b'hello', MSG_OOB)
5
Quoted 1 line
Quoted 1 line
Quoted 1 line
c2.recv(5, MSG_PEEK)
b'hell'
--- net/unix/af_unix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/unix/af_unix.c +1 -1
@@ -2741,6 +2741,7 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state, last = skb =skb_peek (&sk->sk_receive_queue); last_len = last ? last->len :0 ; +again:#if IS_ENABLED (CONFIG_AF_UNIX_OOB )if (skb) { skb =manage_oob (skb, sk, flags, copied);
@@ -2752,7 +2753,6 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state, } }#endif -again:if (skb ==NULL ) {if (copied >= target) goto unlock;
Signature · 1 line
2.30.2
PATCH 2/3 af_unix: Don't peek OOB data without MSG_OOB.
In reply to Kuniyuki IwashimaCurrently, we can read OOB data without MSG_OOB by using MSG_PEEK when OOB data is sitting on the front row, which is apparently wrong.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
from socket import *
c1, c2 =socketpair(AF_UNIX, SOCK_STREAM)c1.send(b'a', MSG_OOB)
1
Quoted 1 line
Quoted 1 line
Quoted 1 line
c2.recv(1, MSG_PEEK | MSG_DONTWAIT)
b'a'
If manage_oob() is called when no data has been copied, we only check if the socket enables SO_OOBINLINE or MSG_PEEK is not used. Otherwise, the skb is returned as is.
However, here we should return NULL if MSG_PEEK is set and no data has been copied.
Also, in such a case, we should not jump to the redo label because we will be caught in the loop and hog the CPU until normal data comes in.
Then, we need to handle skb == NULL case with the if-clause below the manage_oob() block.
With this patch:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
from socket import *
c1, c2 =socketpair(AF_UNIX, SOCK_STREAM)c1.send(b'a', MSG_OOB)
1
Quoted 1 line
Quoted 1 line
Quoted 1 line
c2.recv(1, MSG_PEEK | MSG_DONTWAIT)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
BlockingIOError: [Errno 11] Resource temporarily unavailable
--- net/unix/af_unix.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/unix/af_unix.c +5 -5
@@ -2663,7 +2663,9 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,WRITE_ONCE (u->oob_skb,NULL );consume_skb (skb); } - }else if (!(flags &MSG_PEEK )) { + }else if (flags &MSG_PEEK ) { + skb =NULL ; + }else {skb_unlink (skb, &sk->sk_receive_queue);WRITE_ONCE (u->oob_skb,NULL );if (!WARN_ON_ONCE (skb_unref (skb)))
@@ -2745,11 +2747,9 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,#if IS_ENABLED (CONFIG_AF_UNIX_OOB )if (skb) { skb =manage_oob (skb, sk, flags, copied); -if (!skb) { +if (!skb && copied) {unix_state_unlock (sk); -if (copied) -break ; - goto redo; +break ; } }#endif
Signature · 1 line
2.30.2
PATCH 3/3 af_unix: Prepare MSG_OOB deprecation.
In reply to Kuniyuki IwashimaCommit 314001f0bf92 ("af_unix: Add OOB support") introduced MSG_OOB support for AF_UNIX, and it's about 3 years ago. Since then, MSG_OOB is the playground for syzbot.
MSG_OOB support is guarded with CONFIG_AF_UNIX_OOB, but it's enabled by default and cannot be disabled without editing .config manually because of the lack of prompt.
We recently found 3 wrong behaviours with basic functionality that no one have noticed for 3 years, so it seems there is no real user and even the author is not using OOB feature. [0]
This is a good opportunity to drop MSG_OOB support.
Let's switch the default config to n and add warning so that someone using MSG_OOB in a real workload can notice it before MSG_OOB support is removed completely.
---
Added Fixes tag so that it can be backported to corresponding stable kernels.
--- net/unix/Kconfig | 4 ++-- net/unix/af_unix.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
net/unix/Kconfig +2 -2
@@ -17,9 +17,9 @@ config UNIX Say Y unless you know what you are doing. config AF_UNIX_OOB - bool + bool "Unix MSG_OOB support" depends on UNIX - default y + default n config UNIX_DIAG tristate "UNIX: socket monitoring interface"
net/unix/af_unix.c +2 -0
@@ -2253,6 +2253,8 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg, err = -EOPNOTSUPP ;if (msg->msg_flags &MSG_OOB ) {#if IS_ENABLED (CONFIG_AF_UNIX_OOB ) +pr_warn_once ("MSG_OOB support will be removed in 2025.\n" ); +if (len) len--;else
Signature · 1 line
2.30.2
Re: [PATCH v1 net 3/3] af_unix: Prepare MSG_OOB deprecation.
This feature was added because it was needed by Oracle products. The bugs found are corner cases and happen with new feature, at the time all tests passed. If you do not feel like fixing these bugs that is fine, let me know and I will address them, but removing the feature completely should not be an option.
Plus Amazon has it's own closed/proprietary distribution. If this is an issue please configure your repo to not include this feature. Many distributions choose not to include several features.
Shoaib
Quoted 58 lines · Kuniyuki Iwashima
Commit
314001f0bf92("af_unix: Add OOB support") introducedMSG_OOBsupport forAF_UNIX, and it's about 3 years ago. Since then,MSG_OOBis the playground for syzbot.
MSG_OOBsupport is guarded withCONFIG_AF_UNIX_OOB, but it's enabled by default and cannot be disabled without editing .config manually because of the lack of prompt.We recently found 3 wrong behaviours with basic functionality that no one have noticed for 3 years, so it seems there is no real user and even the author is not using OOB feature. [0]
This is a good opportunity to drop
MSG_OOBsupport.Let's switch the default config to n and add warning so that someone using
MSG_OOBin a real workload can notice it beforeMSG_OOBsupport is removed completely.Fixes 314001f0bf92 ("af_unix: Add OOB support")Signed-off-by Kuniyuki Iwashima <[email protected]>---
Added Fixes tag so that it can be backported to corresponding stable kernels.--- net/unix/Kconfig | 4 ++-- net/unix/af_unix.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)net/unix/Kconfig +2
-2@@ -17,9 +17,9 @@ config UNIX Say Y unless you know what you are doing. config AF_UNIX_OOB - bool + bool "Unix MSG_OOB support" depends on UNIX - default y + default n config UNIX_DIAG tristate "UNIX: socket monitoring interface"net/unix/af_unix.c +2
-0@@ -2253,6 +2253,8 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg, err = -EOPNOTSUPP ;if (msg->msg_flags &MSG_OOB ) {#if IS_ENABLED (CONFIG_AF_UNIX_OOB ) +pr_warn_once ("MSG_OOB support will be removed in 2025.\n" ); +if (len) len--;else
Re: [PATCH v1 net 3/3] af_unix: Prepare MSG_OOB deprecation.
From: Rao Shoaib <[email protected]>
Date: Tue, 9 Apr 2024 17:09:24 -0700
Quoted 1 line
This feature was added because it was needed by Oracle products.
I know. What's about now ?
I just took the silence as no here.
https://lore.kernel.org/netdev/[email protected]/
As I noted in the cover letter, I'm fine to drop this patch if there's a real user.
Quoted 3 lines
The
bugs found are corner cases and happen with new feature, at the time all tests passed.
Yes, but the test was not sufficient.
Quoted 2 lines
If you do not feel like fixing these bugs that is fine, let me know and I will address them,
Please do even if I don't let you know.
Quoted 6 lines
but removing the feature completely
should not be an option.Plus Amazon has it's own closed/proprietary distribution. If this is an issue please configure your repo to not include this feature. Many distributions choose not to include several features.
The problem is that the buggy feature risks many distributions. If not-well-maintained feature is really needed only for a single distro, it should be rather maintained as downstream patch.
If no one is using it, no reason to keep the attack sarface alive.
Re: [PATCH v1 net 3/3] af_unix: Prepare MSG_OOB deprecation.
Quoted 13 lines · Kuniyuki Iwashima
From: Rao Shoaib <[email protected]>
Date: Tue, 9 Apr 2024 17:09:24 -0700Quoted 1 line
This feature was added because it was needed by Oracle products.
I know. What's about now ?
I just took the silence as no here.
https://urldefense.com/v3/__https://lore.kernel.org/netdev/[email protected]/__;!!ACWV5N9M2RV99hQ!Nk1WvCk4-rstASn7PUW4QiAejf0gQ7ktNz-AhuB2UHt9Vx7yUVcfcJ82f9XM3tsDanwnWusycGdUfF4$As I noted in the cover letter, I'm fine to drop this patch if there's a real user.
Quoted 6 lines
Quoted 3 lines
The
bugs found are corner cases and happen with new feature, at the time all tests passed.Yes, but the test was not sufficient.
Yes they were not but we ran the tests that were required and available. If bugs are found later we are responsible for fixing them and we will.
Quoted 6 lines
Quoted 3 lines
If you do not feel like fixing these bugs that is fine, let me know and I will address them,
Please do even if I don't let you know.
The way we use it we have not run into these unusual test cases. If you or anyone runs into any bugs please report and I personally will debug and fix the issue, just like open source is suppose to work.
Quoted 8 lines
Quoted 7 lines
but removing the feature completely
should not be an option.Plus Amazon has it's own closed/proprietary distribution. If this is an issue please configure your repo to not include this feature. Many distributions choose not to include several features.
Quoted 5 lines
The problem is that the buggy feature risks many distributions. If not-well-maintained feature is really needed only for a single distro, it should be rather maintained as downstream patch.
If no one is using it, no reason to keep the attack sarface alive.
Tell me one feature in Linux that does not have bugs?
The feature if used normally works just fine, the bugs that have been found do not cause any stability issue, may be functional issue at best. How many applications do you know use MSG_PEEK that these tests are exploiting.
Plus if it is annoying to you just remove the feature from your private distribution and let the others decide for them selves.
Shoaib
Re: [PATCH v1 net 3/3] af_unix: Prepare MSG_OOB deprecation.
From: Rao Shoaib <[email protected]>
Date: Tue, 9 Apr 2024 17:48:37 -0700
Quoted 6 lines · Kuniyuki Iwashima
Quoted 5 lines
From: Rao Shoaib <[email protected]>
Date: Tue, 9 Apr 2024 17:09:24 -0700Quoted 1 line
This feature was added because it was needed by Oracle products.
I know. What's about now ?
Why do you ingore this again ?
If it's really used in Oracle products, you can just say yes, but it seems no ?
Quoted 12 lines
Quoted 12 lines
I just took the silence as no here.
https://urldefense.com/v3/__https://lore.kernel.org/netdev/[email protected]/__;!!ACWV5N9M2RV99hQ!Nk1WvCk4-rstASn7PUW4QiAejf0gQ7ktNz-AhuB2UHt9Vx7yUVcfcJ82f9XM3tsDanwnWusycGdUfF4$As I noted in the cover letter, I'm fine to drop this patch if there's a real user.
Quoted 3 lines
The
bugs found are corner cases and happen with new feature, at the time all tests passed.
Quoted 5 lines
Quoted 2 lines
Yes, but the test was not sufficient.
Yes they were not but we ran the tests that were required and available. If bugs are found later we are responsible for fixing them and we will.
This is nice,
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
If you do not feel like fixing these bugs that is fine, let me know and I will address them,
Please do even if I don't let you know.
The way we use it we have not run into these unusual test cases. If you or anyone runs into any bugs please report and I personally will debug and fix the issue, just like open source is suppose to work.
but why personally ? because Oracle products no longer use it ? If so, why do you want to keep the feature with no user ?
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
but removing the feature completely
should not be an option.Plus Amazon has it's own closed/proprietary distribution. If this is an issue please configure your repo to not include this feature. Many distributions choose not to include several features.
Quoted 7 lines
Quoted 5 lines
The problem is that the buggy feature risks many distributions. If not-well-maintained feature is really needed only for a single distro, it should be rather maintained as downstream patch.
If no one is using it, no reason to keep the attack sarface alive.
Tell me one feature in Linux that does not have bugs?
I'm not talking about features with no bug. It's fine to have bugs if it's maintained and fixed in timely manner.
I'm talking about a feature with bugs that seems not to be used by anyone nor maintained.
Quoted 2 lines
The feature if used normally works just fine, the bugs that have been found do not cause any stability issue, may be functional issue at best.
It caused memory leaks in some ways easily without admin privilege.
Quoted 2 lines
How many applications do you know use
MSG_PEEKthat these tests are exploiting.
Security is not that way of thinking. Even when the bug is triggered with unusual sequence of calls, it must be fixed, especially on a host that could execute untrusted code.
Quoted 3 lines
Plus if it is annoying to you just remove the feature from your private distribution and let the others decide for them selves.
If no one uses the feature that has bugs without maintenance, it's natural to deprecate it. Then, no one need to be burdened by unnecessary bug fixes.
Re: [PATCH v1 net 3/3] af_unix: Prepare MSG_OOB deprecation.
It is used by Oracle products. File bugs and someone from Oracle will fix it (most likely me). Oracle has addressed any bugs reported in a very timely manner. So in summary the feature is being used and is actively maintained.
You can also turn off the feature in your private/closed distro and not worry about it.
That is all I have to say on this subject.
Shoaib
Quoted 97 lines · Kuniyuki Iwashima
From: Rao Shoaib <[email protected]>
Date: Tue, 9 Apr 2024 17:48:37 -0700Quoted 6 lines · Kuniyuki Iwashima
Quoted 5 lines
From: Rao Shoaib <[email protected]>
Date: Tue, 9 Apr 2024 17:09:24 -0700Quoted 1 line
This feature was added because it was needed by Oracle products.
I know. What's about now ?
Why do you ingore this again ?
If it's really used in Oracle products, you can just say yes, but it seems no ?
Quoted 12 lines
Quoted 12 lines
I just took the silence as no here.
https://urldefense.com/v3/__https://lore.kernel.org/netdev/[email protected]/__;!!ACWV5N9M2RV99hQ!Nk1WvCk4-rstASn7PUW4QiAejf0gQ7ktNz-AhuB2UHt9Vx7yUVcfcJ82f9XM3tsDanwnWusycGdUfF4$As I noted in the cover letter, I'm fine to drop this patch if there's a real user.
Quoted 3 lines
The
bugs found are corner cases and happen with new feature, at the time all tests passed.Quoted 5 lines
Quoted 2 lines
Yes, but the test was not sufficient.
Yes they were not but we ran the tests that were required and available. If bugs are found later we are responsible for fixing them and we will.
This is nice,
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
If you do not feel like fixing these bugs that is fine, let me know and I will address them,
Please do even if I don't let you know.
The way we use it we have not run into these unusual test cases. If you or anyone runs into any bugs please report and I personally will debug and fix the issue, just like open source is suppose to work.
but why personally ? because Oracle products no longer use it ? If so, why do you want to keep the feature with no user ?
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
but removing the feature completely
should not be an option.Plus Amazon has it's own closed/proprietary distribution. If this is an issue please configure your repo to not include this feature. Many distributions choose not to include several features.
Quoted 7 lines
Quoted 5 lines
The problem is that the buggy feature risks many distributions. If not-well-maintained feature is really needed only for a single distro, it should be rather maintained as downstream patch.
If no one is using it, no reason to keep the attack sarface alive.
Tell me one feature in Linux that does not have bugs?
I'm not talking about features with no bug. It's fine to have bugs if it's maintained and fixed in timely manner.
I'm talking about a feature with bugs that seems not to be used by anyone nor maintained.
Quoted 2 lines
The feature if used normally works just fine, the bugs that have been found do not cause any stability issue, may be functional issue at best.
It caused memory leaks in some ways easily without admin privilege.
Quoted 2 lines
How many applications do you know use
MSG_PEEKthat these tests are exploiting.Security is not that way of thinking. Even when the bug is triggered with unusual sequence of calls, it must be fixed, especially on a host that could execute untrusted code.
Quoted 3 lines
Plus if it is annoying to you just remove the feature from your private distribution and let the others decide for them selves.
If no one uses the feature that has bugs without maintenance, it's natural to deprecate it. Then, no one need to be burdened by unnecessary bug fixes.
Re: [PATCH v1 net 3/3] af_unix: Prepare MSG_OOB deprecation.
From: Rao Shoaib <[email protected]>
Date: Wed, 10 Apr 2024 01:36:01 -0700
Quoted 1 line
It is used by Oracle products.
This is what I wanted to know, and then I'm fine to respin v2 without this patch.
Thank you.
Quoted 11 lines
File bugs and someone from Oracle will
fix it (most likely me). Oracle has addressed any bugs reported in a very timely manner. So in summary the feature is being used and is actively maintained.You can also turn off the feature in your private/closed distro and not worry about it.
That is all I have to say on this subject.
Shoaib