Guard against empty file lock status

Submitted by Nicolas Viennot on Oct. 1, 2019, 8:56 p.m.

Details

Message ID be90b56b496947a6a7c60c31537e403d@EXMBDFT10.ad.twosigma.com
State Accepted
Series "Guard against empty file lock status"
Commit 48ebf086d3e3529a5470203ed3613f1affb57846
Headers show

Commit Message

Nicolas Viennot Oct. 1, 2019, 8:56 p.m.
The lock status string may be empty. This can happen when the owner of
the lock is invisible from our PID namespace. This unfortunate behavior
is fixed in kernels v4.19 and up (see commit 1cf8e5de40)

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
---
 criu/proc_parse.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 97f82ee0..d67392a1 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -1669,17 +1669,27 @@  static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg)
 		if (fdinfo_field(str, "lock")) {
 			struct file_lock *fl;
 			struct fdinfo_common *fdinfo = arg;
+			char *flock_status = str+sizeof("lock:\t")-1;
 
 			if (type != FD_TYPES__UND)
 				continue;
 
+			/*
+			 * The lock status can be empty when the owner of the
+			 * lock is invisible from our PID namespace.
+			 * This unfortunate behavior is fixed in kernels v4.19
+			 * and up (see commit 1cf8e5de40).
+			 */
+			if (flock_status[0] == '\0')
+				continue;
+
 			fl = alloc_file_lock();
 			if (!fl) {
 				pr_perror("Alloc file lock failed!");
 				goto out;
 			}
 
-			if (parse_file_lock_buf(str + 6, fl, 0)) {
+			if (parse_file_lock_buf(flock_status, fl, 0)) {
 				xfree(fl);
 				goto parse_err;
 			}

Comments

Andrei Vagin Oct. 7, 2019, 5 p.m.
Applied, thanks!

On Tue, Oct 01, 2019 at 08:56:26PM +0000, Nicolas Viennot wrote:
> The lock status string may be empty. This can happen when the owner of
> the lock is invisible from our PID namespace. This unfortunate behavior
> is fixed in kernels v4.19 and up (see commit 1cf8e5de40)
> 
> Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
> ---
>  criu/proc_parse.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/criu/proc_parse.c b/criu/proc_parse.c
> index 97f82ee0..d67392a1 100644
> --- a/criu/proc_parse.c
> +++ b/criu/proc_parse.c
> @@ -1669,17 +1669,27 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg)
>  		if (fdinfo_field(str, "lock")) {
>  			struct file_lock *fl;
>  			struct fdinfo_common *fdinfo = arg;
> +			char *flock_status = str+sizeof("lock:\t")-1;
>  
>  			if (type != FD_TYPES__UND)
>  				continue;
>  
> +			/*
> +			 * The lock status can be empty when the owner of the
> +			 * lock is invisible from our PID namespace.
> +			 * This unfortunate behavior is fixed in kernels v4.19
> +			 * and up (see commit 1cf8e5de40).
> +			 */
> +			if (flock_status[0] == '\0')
> +				continue;
> +
>  			fl = alloc_file_lock();
>  			if (!fl) {
>  				pr_perror("Alloc file lock failed!");
>  				goto out;
>  			}
>  
> -			if (parse_file_lock_buf(str + 6, fl, 0)) {
> +			if (parse_file_lock_buf(flock_status, fl, 0)) {
>  				xfree(fl);
>  				goto parse_err;
>  			}
> -- 
> 2.19.1
> 
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu