Skip to contentSkip to conversation

fs/ceph/mds_client: pass cred pointer to ceph_mds_auth_match()

PATCH Applied Max Kellermann 3 participants 6 messages Nov 23, 2024 – Nov 25, 2024

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

PATCH 1/2 fs/ceph/mds_client: pass cred pointer to ceph_mds_auth_match()

This eliminates a redundant get_current_cred() call, because ceph_mds_check_access() has already obtained this pointer.

As a side effect, this also fixes a reference leak in ceph_mds_auth_match(): by omitting the get_current_cred() call, no additional cred reference is taken.

Fixes 596afb0b8933 ("ceph: add ceph_mds_check_access() helper")
---
 fs/ceph/mds_client.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ceph/mds_client.c +2 -2
index 6baec1387f7d..e8a5994de8b6 100644
@@ -5615,9 +5615,9 @@ void send_flush_mdlog(struct ceph_mds_session *s)
 
 static int ceph_mds_auth_match(struct ceph_mds_client *mdsc,
 			       struct ceph_mds_cap_auth *auth,
+			       const struct cred *cred,
 			       char *tpath)
 {
-	const struct cred *cred = get_current_cred();
 	u32 caller_uid = from_kuid(&init_user_ns, cred->fsuid);
 	u32 caller_gid = from_kgid(&init_user_ns, cred->fsgid);
 	struct ceph_client *cl = mdsc->fsc->client;
@@ -5740,7 +5740,7 @@ int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask)
 	for (i = 0; i < mdsc->s_cap_auths_num; i++) {
 		struct ceph_mds_cap_auth *s = &mdsc->s_cap_auths[i];
 
-		err = ceph_mds_auth_match(mdsc, s, tpath);
+		err = ceph_mds_auth_match(mdsc, s, cred, tpath);
 		if (err < 0) {
 			return err;
 		} else if (err > 0) {
Signature · 1 line
2.45.2
#1 lore raw

PATCH 2/2 fs/ceph/mds_client: fix cred leak in ceph_mds_check_access()

get_current_cred() increments the reference counter, but the put_cred() call was missing.

Fixes 596afb0b8933 ("ceph: add ceph_mds_check_access() helper")
---
 fs/ceph/mds_client.c | 3 +++
 1 file changed, 3 insertions(+)
fs/ceph/mds_client.c +3 -0
index e8a5994de8b6..35d83c8c2874 100644
@@ -5742,6 +5742,7 @@ int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask)
 
 		err = ceph_mds_auth_match(mdsc, s, cred, tpath);
 		if (err < 0) {
+			put_cred(cred);
 			return err;
 		} else if (err > 0) {
 			/* always follow the last auth caps' permision */
@@ -5757,6 +5758,8 @@ int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask)
 		}
 	}
 
+	put_cred(cred);
+
 	doutc(cl, "root_squash_perms %d, rw_perms_s %p\n", root_squash_perms,
 	      rw_perms_s);
 	if (root_squash_perms && rw_perms_s == NULL) {
Signature · 1 line
2.45.2
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] fs/ceph/mds_client: fix cred leak in ceph_mds_check_access()

Quoted 23 lines · Max Kellermann

get_current_cred() increments the reference counter, but the put_cred() call was missing.

Fixes 596afb0b8933 ("ceph: add ceph_mds_check_access() helper")
---
  fs/ceph/mds_client.c | 3 +++
  1 file changed, 3 insertions(+)
fs/ceph/mds_client.c +1 -0
index e8a5994de8b6..35d83c8c2874 100644
@@ -5742,6 +5742,7 @@ int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask)
 
  		err = ceph_mds_auth_match(mdsc, s, cred, tpath);
  		if (err < 0) {
+			put_cred(cred);
  			return err;
  		} else if (err > 0) {
  			/* always follow the last auth caps' permision */

fs/ceph/mds_client.c int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask) · line 5765

Quoted 8 lines
fs/ceph/mds_client.c +2 -0
@@ -5757,6 +5758,8 @@ int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask)
  		}
  	}
 
+	put_cred(cred);
+
  	doutc(cl, "root_squash_perms %d, rw_perms_s %p\n", root_squash_perms,
  	      rw_perms_s);
  	if (root_squash_perms && rw_perms_s == NULL) {

Good catch.

maintainer Applied
#3 lore raw

Re: [PATCH 2/2] fs/ceph/mds_client: fix cred leak in ceph_mds_check_access()

Quoted 37 lines · Xiubo Li
Quoted 23 lines · Max Kellermann

get_current_cred() increments the reference counter, but the put_cred() call was missing.

Fixes 596afb0b8933 ("ceph: add ceph_mds_check_access() helper")
---
  fs/ceph/mds_client.c | 3 +++
  1 file changed, 3 insertions(+)
fs/ceph/mds_client.c +1 -0
index e8a5994de8b6..35d83c8c2874 100644
@@ -5742,6 +5742,7 @@ int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask)
 
              err = ceph_mds_auth_match(mdsc, s, cred, tpath);
              if (err < 0) {
+                     put_cred(cred);
                      return err;
              } else if (err > 0) {
                      /* always follow the last auth caps' permision */

fs/ceph/mds_client.c int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask) · line 5765

Quoted 8 lines
fs/ceph/mds_client.c +2 -0
@@ -5757,6 +5758,8 @@ int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask)
              }
      }
 
+     put_cred(cred);
+
      doutc(cl, "root_squash_perms %d, rw_perms_s %p\n", root_squash_perms,
            rw_perms_s);
      if (root_squash_perms && rw_perms_s == NULL) {

Good catch.

Quoted 1 line

Applied.

Thanks,

Ilya

Reviewed-by on v1 1/2
#4 lore raw
In reply to Max Kellermann
Quoted 30 lines · Max Kellermann

This eliminates a redundant get_current_cred() call, because ceph_mds_check_access() has already obtained this pointer.

As a side effect, this also fixes a reference leak in ceph_mds_auth_match(): by omitting the get_current_cred() call, no additional cred reference is taken.

Fixes 596afb0b8933 ("ceph: add ceph_mds_check_access() helper")
---
  fs/ceph/mds_client.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/ceph/mds_client.c +1 -1
index 6baec1387f7d..e8a5994de8b6 100644
@@ -5615,9 +5615,9 @@ void send_flush_mdlog(struct ceph_mds_session *s)
 
  static int ceph_mds_auth_match(struct ceph_mds_client *mdsc,
  			       struct ceph_mds_cap_auth *auth,
+			       const struct cred *cred,
  			       char *tpath)
  {
-	const struct cred *cred = get_current_cred();
  	u32 caller_uid = from_kuid(&init_user_ns, cred->fsuid);
  	u32 caller_gid = from_kgid(&init_user_ns, cred->fsgid);
  	struct ceph_client *cl = mdsc->fsc->client;

fs/ceph/mds_client.c int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask) · line 5746

Quoted 8 lines
fs/ceph/mds_client.c +1 -1
@@ -5740,7 +5740,7 @@ int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask)
  	for (i = 0; i < mdsc->s_cap_auths_num; i++) {
  		struct ceph_mds_cap_auth *s = &mdsc->s_cap_auths[i];
 
-		err = ceph_mds_auth_match(mdsc, s, tpath);
+		err = ceph_mds_auth_match(mdsc, s, cred, tpath);
  		if (err < 0) {
  			return err;
  		} else if (err > 0) {

Good catch.

maintainer Applied
#5 lore raw
Quoted 44 lines · Xiubo Li
Quoted 30 lines · Max Kellermann

This eliminates a redundant get_current_cred() call, because ceph_mds_check_access() has already obtained this pointer.

As a side effect, this also fixes a reference leak in ceph_mds_auth_match(): by omitting the get_current_cred() call, no additional cred reference is taken.

Fixes 596afb0b8933 ("ceph: add ceph_mds_check_access() helper")
---
  fs/ceph/mds_client.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/ceph/mds_client.c +1 -1
index 6baec1387f7d..e8a5994de8b6 100644
@@ -5615,9 +5615,9 @@ void send_flush_mdlog(struct ceph_mds_session *s)
 
  static int ceph_mds_auth_match(struct ceph_mds_client *mdsc,
                             struct ceph_mds_cap_auth *auth,
+                            const struct cred *cred,
                             char *tpath)
  {
-     const struct cred *cred = get_current_cred();
      u32 caller_uid = from_kuid(&init_user_ns, cred->fsuid);
      u32 caller_gid = from_kgid(&init_user_ns, cred->fsgid);
      struct ceph_client *cl = mdsc->fsc->client;

fs/ceph/mds_client.c int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask) · line 5746

Quoted 8 lines
fs/ceph/mds_client.c +1 -1
@@ -5740,7 +5740,7 @@ int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask)
      for (i = 0; i < mdsc->s_cap_auths_num; i++) {
              struct ceph_mds_cap_auth *s = &mdsc->s_cap_auths[i];
 
-             err = ceph_mds_auth_match(mdsc, s, tpath);
+             err = ceph_mds_auth_match(mdsc, s, cred, tpath);
              if (err < 0) {
                      return err;
              } else if (err > 0) {

Good catch.

Quoted 1 line

Applied.

Thanks,

Ilya