Skip to contentSkip to conversation

Before clearing the capability bounding set, check if we have the cap

PATCH In review [email protected] 3 participants 4 messages Jun 12, 2012 – Jun 19, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Before clearing the capability bounding set, check if we have the cap

From: Harald Hoyer <[email protected]>

PR_CAPBSET_DROP can return EINVAL, if an older kernel does support some capabilities, which are defined by CAP_LAST_CAP, which results in a failure of the service.

For example kernel 3.4 errors on CAP_EPOLLWAKEUP, which was newly introduced in 3.5.

So, for future capabilities, we clear until we get an EINVAL for PR_CAPBSET_READ.

---
 support/nsm/file.c      |    2 +-
 utils/nfsdcld/nfsdcld.c |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
support/nsm/file.c +1 -1
index 5476446..4711c2c 100644
@@ -386,7 +386,7 @@ prune_bounding_set(void)
 	}
 
 	/* prune the bounding set to nothing */
-	for (i = 0; i <= CAP_LAST_CAP; ++i) {
+	for (i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >=0 ; ++i) {
 		ret = prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
 		if (ret) {
 			xlog(L_ERROR, "Unable to prune capability %lu from "
utils/nfsdcld/nfsdcld.c +2 -2
index e7af4e3..473d069 100644
@@ -102,8 +102,8 @@ cld_set_caps(void)
 	}
 
 	/* prune the bounding set to nothing */
-	for (i = 0; i <= CAP_LAST_CAP; ++i) {
-		ret = prctl(PR_CAPBSET_DROP, i);
+	for (i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0 ; ++i) {
+		ret = prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
 		if (ret) {
 			xlog(L_ERROR, "Unable to prune capability %lu from "
 				      "bounding set: %m", i);
Signature · 1 line
1.7.10.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 34 lines · On Tue, 12 Jun 2012 13:51:06 +0200 [email protected] wrote:

From: Harald Hoyer <[email protected]>

PR_CAPBSET_DROP can return EINVAL, if an older kernel does support some capabilities, which are defined by CAP_LAST_CAP, which results in a failure of the service.

For example kernel 3.4 errors on CAP_EPOLLWAKEUP, which was newly introduced in 3.5.

So, for future capabilities, we clear until we get an EINVAL for PR_CAPBSET_READ.

---
 support/nsm/file.c      |    2 +-
 utils/nfsdcld/nfsdcld.c |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
support/nsm/file.c +1 -1
index 5476446..4711c2c 100644
@@ -386,7 +386,7 @@ prune_bounding_set(void)
 	}
 
 	/* prune the bounding set to nothing */
-	for (i = 0; i <= CAP_LAST_CAP; ++i) {
+	for (i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >=0 ; ++i) {
 		ret = prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
 		if (ret) {
 			xlog(L_ERROR, "Unable to prune capability %lu from "
utils/nfsdcld/nfsdcld.c +0 -0
index e7af4e3..473d069 100644

utils/nfsdcld/nfsdcld.c cld_set_caps(void) · line 109

Quoted 10 lines
utils/nfsdcld/nfsdcld.c +2 -2
@@ -102,8 +102,8 @@ cld_set_caps(void)
 	}
 
 	/* prune the bounding set to nothing */
-	for (i = 0; i <= CAP_LAST_CAP; ++i) {
-		ret = prctl(PR_CAPBSET_DROP, i);
+	for (i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0 ; ++i) {
+		ret = prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
 		if (ret) {
 			xlog(L_ERROR, "Unable to prune capability %lu from "
 				      "bounding set: %m", i);

Thanks, looks like a reasonable method. Did you find this by inspection, or did you or someone else hit the problem?

#2 lore raw
Quoted 51 lines · Jeff Layton
Quoted 34 lines · On Tue, 12 Jun 2012 13:51:06 +0200 [email protected] wrote:

From: Harald Hoyer <[email protected]>

PR_CAPBSET_DROP can return EINVAL, if an older kernel does support some capabilities, which are defined by CAP_LAST_CAP, which results in a failure of the service.

For example kernel 3.4 errors on CAP_EPOLLWAKEUP, which was newly introduced in 3.5.

So, for future capabilities, we clear until we get an EINVAL for PR_CAPBSET_READ.

---
 support/nsm/file.c      |    2 +-
 utils/nfsdcld/nfsdcld.c |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
support/nsm/file.c +1 -1
index 5476446..4711c2c 100644
@@ -386,7 +386,7 @@ prune_bounding_set(void)
 	}
 
 	/* prune the bounding set to nothing */
-	for (i = 0; i <= CAP_LAST_CAP; ++i) {
+	for (i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >=0 ; ++i) {
 		ret = prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
 		if (ret) {
 			xlog(L_ERROR, "Unable to prune capability %lu from "
utils/nfsdcld/nfsdcld.c +0 -0
index e7af4e3..473d069 100644

utils/nfsdcld/nfsdcld.c cld_set_caps(void) · line 109

Quoted 10 lines
utils/nfsdcld/nfsdcld.c +2 -2
@@ -102,8 +102,8 @@ cld_set_caps(void)
 	}
 
 	/* prune the bounding set to nothing */
-	for (i = 0; i <= CAP_LAST_CAP; ++i) {
-		ret = prctl(PR_CAPBSET_DROP, i);
+	for (i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0 ; ++i) {
+		ret = prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
 		if (ret) {
 			xlog(L_ERROR, "Unable to prune capability %lu from "
 				      "bounding set: %m", i);

Thanks, looks like a reasonable method. Did you find this by inspection, or did you or someone else hit the problem?

Quoted 2 lines

I am currently running rawhide with kernel 3.4.0 and rpc.statd failed.

rpc.statd[19338]: Unable to prune capability 36 from bounding set: Invalid argument

#3 lore raw
In reply to [email protected]
Quoted 11 lines · On 06/12/2012 07:51 AM, [email protected] wrote:

From: Harald Hoyer <[email protected]>

PR_CAPBSET_DROP can return EINVAL, if an older kernel does support some capabilities, which are defined by CAP_LAST_CAP, which results in a failure of the service.

For example kernel 3.4 errors on CAP_EPOLLWAKEUP, which was newly introduced in 3.5.

So, for future capabilities, we clear until we get an EINVAL for PR_CAPBSET_READ.

Committed...

steved.

Quoted 33 lines
---
 support/nsm/file.c      |    2 +-
 utils/nfsdcld/nfsdcld.c |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
support/nsm/file.c +1 -1
index 5476446..4711c2c 100644
@@ -386,7 +386,7 @@ prune_bounding_set(void)
 	}
 
 	/* prune the bounding set to nothing */
-	for (i = 0; i <= CAP_LAST_CAP; ++i) {
+	for (i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >=0 ; ++i) {
 		ret = prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
 		if (ret) {
 			xlog(L_ERROR, "Unable to prune capability %lu from "
utils/nfsdcld/nfsdcld.c +2 -2
index e7af4e3..473d069 100644
@@ -102,8 +102,8 @@ cld_set_caps(void)
 	}
 
 	/* prune the bounding set to nothing */
-	for (i = 0; i <= CAP_LAST_CAP; ++i) {
-		ret = prctl(PR_CAPBSET_DROP, i);
+	for (i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0 ; ++i) {
+		ret = prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
 		if (ret) {
 			xlog(L_ERROR, "Unable to prune capability %lu from "
 				      "bounding set: %m", i);