[CRIU] [PATCH 4/5] sk-unix: Add trivial name resolver for sockets with relative names

Pavel Emelyanov xemul at parallels.com
Tue Jul 28 05:31:48 PDT 2015


On 07/28/2015 03:27 PM, Cyrill Gorcunov wrote:
> On Tue, Jul 28, 2015 at 03:11:48PM +0300, Pavel Emelyanov wrote:
>>>  
>>> +static int resolve_rel_name(struct unix_sk_desc *sk, const struct fd_parms *p)
>>> +{
>>> +	rel_name_desc_t *rel_name = sk->rel_name;
>>> +	const char *dirs[] = { "cwd", "root" };
>>> +	int mntns_root, i;
>>> +	struct ns_id *ns;
>>> +
>>> +	ns = lookup_ns_by_id(root_item->ids->mnt_ns_id, &mnt_ns_desc);
>>
>> This should be task's mntns, not some arbitrary one :)
> 
> True, thanks!
> 
>>>  static int dump_one_unix_fd(int lfd, u32 id, const struct fd_parms *p)
>>>  {
>>>  	struct unix_sk_desc *sk, *peer;
>>
>>> @@ -714,6 +808,9 @@ static int post_open_unix_sk(struct file_desc *d, int fd)
>>>  	addr.sun_family = AF_UNIX;
>>>  	memcpy(&addr.sun_path, peer->name, peer->ue->name.len);
>>>  
>>> +	if (prep_unix_sk_cwd(ui))
>>
>> You do this to make subsequent connect() resolve the name properly,
>> so the prep_ should be called on peer, not on ui, shouldn't it?
> 
> Yeah, thanks!

And we need test for that too ;)

>>
>>> +		return -1;
>>> +
>>>  	if (connect(fd, (struct sockaddr *)&addr,
>>>  				sizeof(addr.sun_family) +
>>>  				peer->ue->name.len) < 0) {
>>> @@ -754,6 +851,9 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui)
>>>  	addr.sun_family = AF_UNIX;
>>>  	memcpy(&addr.sun_path, ui->name, ui->ue->name.len);
>>>  
>>> +	if (prep_unix_sk_cwd(ui))
>>> +		return -1;
>>> +
>>>  	if (bind(sk, (struct sockaddr *)&addr,
>>>  				sizeof(addr.sun_family) + ui->ue->name.len)) {
>>>  		pr_perror("Can't bind socket");
>>> @@ -769,8 +869,11 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui)
>>>  			return -1;
>>>  		}
>>>  
>>> -		memcpy(fname, ui->name, ui->ue->name.len);
>>> -		fname[ui->ue->name.len] = '\0';
>>> +		if (!ui->name_dir) {
>>> +			memcpy(fname, ui->name, ui->ue->name.len);
>>> +			fname[ui->ue->name.len] = '\0';
>>> +		} else
>>> +			snprintf(fname, PATH_MAX, "%s/%s", ui->name_dir, ui->name);
>>>  
>>>  		if (chown(fname, perms->uid, perms->gid) == -1) {
>>
>> Won't chownat() be better?
> 
> Sure, won't hurt. I'll update and resend
> .
> 



More information about the CRIU mailing list