[v2,03/15] sysctl: add req->has to mark successful sysctl_op request

Submitted by Pavel Tikhomirov on April 20, 2016, 2:42 p.m.

Details

Message ID 1461163376-32668-4-git-send-email-ptikhomirov@virtuozzo.com
State Rejected
Series "net/ipv6: c/r dev/default/all conf ops"
Headers show

Commit Message

Pavel Tikhomirov April 20, 2016, 2:42 p.m.
must be carefull allocating memory for sysctl_req as trash values
can cause segmentation fault

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
 criu/include/sysctl.h | 1 +
 criu/sysctl.c         | 8 ++++++++
 2 files changed, 9 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/include/sysctl.h b/criu/include/sysctl.h
index b949a40..9ee93c6 100644
--- a/criu/include/sysctl.h
+++ b/criu/include/sysctl.h
@@ -6,6 +6,7 @@  struct sysctl_req {
 	void	*arg;
 	int	type;
 	int	flags;
+	int	*has;
 };
 
 extern int sysctl_op(struct sysctl_req *req, size_t nr_req, int op, unsigned int ns);
diff --git a/criu/sysctl.c b/criu/sysctl.c
index 21ae4ce..bd584bd 100644
--- a/criu/sysctl.c
+++ b/criu/sysctl.c
@@ -261,6 +261,10 @@  static int __userns_sysctl_op(void *arg, int proc_fd, pid_t pid)
 			goto out;
 		}
 
+		if (req->has)
+			/* sysctl in question exists */
+			*req->has = 1;
+
 		/* save a pointer to the req, so we don't need to recompute its
 		 * location
 		 */
@@ -371,6 +375,10 @@  static int __nonuserns_sysctl_op(struct sysctl_req *req, size_t nr_req, int op)
 			goto out;
 		}
 
+		if (req->has)
+			/* sysctl in question exists */
+			 *req->has = 1;
+
 		ret = do_sysctl_op(fd, req, op);
 		if (ret)
 			goto out;

Comments

Pavel Emelianov April 21, 2016, 2:09 p.m.
On 04/20/2016 05:42 PM, Pavel Tikhomirov wrote:
> must be carefull allocating memory for sysctl_req as trash values
> can cause segmentation fault
> 
> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
> ---
>  criu/include/sysctl.h | 1 +
>  criu/sysctl.c         | 8 ++++++++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/criu/include/sysctl.h b/criu/include/sysctl.h
> index b949a40..9ee93c6 100644
> --- a/criu/include/sysctl.h
> +++ b/criu/include/sysctl.h
> @@ -6,6 +6,7 @@ struct sysctl_req {
>  	void	*arg;
>  	int	type;
>  	int	flags;
> +	int	*has;

I'd better report back some bit (in case of sysctl was missing) in the flags field.

>  };
>  
>  extern int sysctl_op(struct sysctl_req *req, size_t nr_req, int op, unsigned int ns);
> diff --git a/criu/sysctl.c b/criu/sysctl.c
> index 21ae4ce..bd584bd 100644
> --- a/criu/sysctl.c
> +++ b/criu/sysctl.c
> @@ -261,6 +261,10 @@ static int __userns_sysctl_op(void *arg, int proc_fd, pid_t pid)
>  			goto out;
>  		}
>  
> +		if (req->has)
> +			/* sysctl in question exists */
> +			*req->has = 1;
> +
>  		/* save a pointer to the req, so we don't need to recompute its
>  		 * location
>  		 */
> @@ -371,6 +375,10 @@ static int __nonuserns_sysctl_op(struct sysctl_req *req, size_t nr_req, int op)
>  			goto out;
>  		}
>  
> +		if (req->has)
> +			/* sysctl in question exists */
> +			 *req->has = 1;
> +
>  		ret = do_sysctl_op(fd, req, op);
>  		if (ret)
>  			goto out;
>
Pavel Tikhomirov April 21, 2016, 2:32 p.m.
On 04/21/2016 05:09 PM, Pavel Emelyanov wrote:
> On 04/20/2016 05:42 PM, Pavel Tikhomirov wrote:
>> must be carefull allocating memory for sysctl_req as trash values
>> can cause segmentation fault
>>
>> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
>> ---
>>   criu/include/sysctl.h | 1 +
>>   criu/sysctl.c         | 8 ++++++++
>>   2 files changed, 9 insertions(+)
>>
>> diff --git a/criu/include/sysctl.h b/criu/include/sysctl.h
>> index b949a40..9ee93c6 100644
>> --- a/criu/include/sysctl.h
>> +++ b/criu/include/sysctl.h
>> @@ -6,6 +6,7 @@ struct sysctl_req {
>>   	void	*arg;
>>   	int	type;
>>   	int	flags;
>> +	int	*has;
>
> I'd better report back some bit (in case of sysctl was missing) in the flags field.

In case of CTL_READ we fortunately have identic mapping conf[i] to 
req[i], so I can write conf[i].has_ fields checking req[i].flags, OK.

>
>>   };
>>
>>   extern int sysctl_op(struct sysctl_req *req, size_t nr_req, int op, unsigned int ns);
>> diff --git a/criu/sysctl.c b/criu/sysctl.c
>> index 21ae4ce..bd584bd 100644
>> --- a/criu/sysctl.c
>> +++ b/criu/sysctl.c
>> @@ -261,6 +261,10 @@ static int __userns_sysctl_op(void *arg, int proc_fd, pid_t pid)
>>   			goto out;
>>   		}
>>
>> +		if (req->has)
>> +			/* sysctl in question exists */
>> +			*req->has = 1;
>> +
>>   		/* save a pointer to the req, so we don't need to recompute its
>>   		 * location
>>   		 */
>> @@ -371,6 +375,10 @@ static int __nonuserns_sysctl_op(struct sysctl_req *req, size_t nr_req, int op)
>>   			goto out;
>>   		}
>>
>> +		if (req->has)
>> +			/* sysctl in question exists */
>> +			 *req->has = 1;
>> +
>>   		ret = do_sysctl_op(fd, req, op);
>>   		if (ret)
>>   			goto out;
>>
>