Skip to contentSkip to conversation

tools/libxenforeignmemory: add a call to restrict the handle

PATCH In review Paul Durrant 4 participants 9 messages Mar 22, 2017 – Mar 27, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/libxenforeignmemory: add a call to restrict the handle

Commit 8ef5f344d061 "tools/libxendevicemodel: add a call to restrict the handle" added a function to the devicemodel interface to restrict operations through the API to a specific domain, where a capable under- lying privcmd driver exists.

This patch adds similar functionality to the xenforeignmemory API. This will be necessary (as much as xendevicemodel restriction) for limiting the scope of device models to specific domains.

NOTE: My patch to the linux kernel [1] added the appropriate checks to
the foreign memory ioctls.

[1] https://git.kernel.org/cgit/linux/kernel/git/ostr/linux.git/commit/?id=4610d240

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/libs/foreignmemory/core.c                     |  6 ++++++
 tools/libs/foreignmemory/freebsd.c                  |  7 +++++++
 tools/libs/foreignmemory/include/xenforeignmemory.h | 11 +++++++++++
 tools/libs/foreignmemory/libxenforeignmemory.map    |  1 +
 tools/libs/foreignmemory/linux.c                    |  6 ++++++
 tools/libs/foreignmemory/minios.c                   |  7 +++++++
 tools/libs/foreignmemory/netbsd.c                   |  7 +++++++
 tools/libs/foreignmemory/private.h                  |  3 +++
 tools/libs/foreignmemory/solaris.c                  |  7 +++++++
 9 files changed, 55 insertions(+)
tools/libs/foreignmemory/core.c +6 -0
index a872b95..0ebd429 100644
@@ -106,6 +106,12 @@ int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
     return osdep_xenforeignmemory_unmap(fmem, addr, num);
 }
 
+int xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                              domid_t domid)
+{
+    return osdep_xenforeignmemory_restrict(fmem, domid);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/foreignmemory/freebsd.c +7 -0
index ef08b6c..f6cd08c 100644
@@ -96,6 +96,13 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
     return munmap(addr, num << PAGE_SHIFT);
 }
 
+int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                                    domid_t domid)
+{
+    errno = -EOPNOTSUPP;
+    return -1;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/foreignmemory/include/xenforeignmemory.h +11 -0
index 92b9277..d5be648 100644
@@ -115,6 +115,17 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom,
 int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
                            void *addr, size_t pages);
 
+/**
+ * This function restricts the use of this handle to the specified
+ * domain.
+ *
+ * @parm fmem handle to the open foreignmemory interface
+ * @parm domid the domain id
+ * @return 0 on success, -1 on failure.
+ */
+int xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                              domid_t domid);
+
 #endif
 
 /*
tools/libs/foreignmemory/libxenforeignmemory.map +1 -0
index df206b3..5c9806c 100644
@@ -4,5 +4,6 @@ VERS_1.0 {
 		xenforeignmemory_close;
 		xenforeignmemory_map;
 		xenforeignmemory_unmap;
+		xenforeignmemory_restrict;
 	local: *; /* Do not expose anything by default */
 };
tools/libs/foreignmemory/linux.c +6 -0
index 423c744..320bb21 100644
@@ -272,6 +272,12 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
     return munmap(addr, num << PAGE_SHIFT);
 }
 
+int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                                    domid_t domid)
+{
+    return ioctl(fmem->fd, IOCTL_PRIVCMD_RESTRICT, &domid);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/foreignmemory/minios.c +7 -0
index 6dc97bd..2dd4910 100644
@@ -58,6 +58,13 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
     return munmap(addr, num << PAGE_SHIFT);
 }
 
+int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                                    domid_t domid)
+{
+    errno = -EOPNOTSUPP;
+    return -1;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/foreignmemory/netbsd.c +7 -0
index 08f4964..af3a1a4 100644
@@ -100,6 +100,13 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
     return munmap(addr, num*XC_PAGE_SIZE);
 }
 
+int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                                    domid_t domid)
+{
+    errno = -EOPNOTSUPP;
+    return -1;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/foreignmemory/private.h +3 -0
index 9cc7814..ed7ec7a 100644
@@ -32,6 +32,9 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
 int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
                                  void *addr, size_t num);
 
+int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                                    domid_t domid);
+
 #if defined(__NetBSD__) || defined(__sun__)
 /* Strictly compat for those two only only */
 void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom,
tools/libs/foreignmemory/solaris.c +7 -0
index e925a29..fe7bb45 100644
@@ -98,6 +98,13 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
     return munmap(addr, num*XC_PAGE_SIZE);
 }
 
+int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                                    domid_t domid)
+{
+    errno = -EOPNOTSUPP;
+    return -1;
+}
+
 /*
  * Local variables:
  * mode: C
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Paul Durrant

Commit 8ef5f344d061 "tools/libxendevicemodel: add a call to restrict the handle" added a function to the devicemodel interface to restrict operations through the API to a specific domain, where a capable under- lying privcmd driver exists.

This patch adds similar functionality to the xenforeignmemory API. This will be necessary (as much as xendevicemodel restriction) for limiting the scope of device models to specific domains.

Quoted 6 lines

NOTE: My patch to the linux kernel [1] added the appropriate checks to
the foreign memory ioctls.

[1] https://git.kernel.org/cgit/linux/kernel/git/ostr/linux.git/commit/?id=4610d240

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
In reply to Paul Durrant

tools/libs/foreignmemory/libxenforeignmemory.map VERS_1.0 { · line 9

Quoted 11 lines · Paul Durrant
tools/libs/foreignmemory/libxenforeignmemory.map +1 -0
index df206b3..5c9806c 100644
@@ -4,5 +4,6 @@ VERS_1.0 {
 		xenforeignmemory_close;
 		xenforeignmemory_map;
 		xenforeignmemory_unmap;
+		xenforeignmemory_restrict;
 	local: *; /* Do not expose anything by default */
 };

This isn't correct.

New functions like this need to bump at least the SO minor version, like c/s f1446de4ba

Fixing this is a blocker to releasing 4.9

Also, we should really get automatic ABI checking built into the release process, to prevent mistakes like this from happening accidentally.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 25 lines

-----Original Message-----
From: Andrew Cooper
Sent: 24 March 2017 20:10
To: Paul Durrant <[email protected]>; [email protected]
Cc: Wei Liu <[email protected]>; Ian Jackson <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [Xen-devel] [PATCH] tools/libxenforeignmemory: add a call to restrict the handle

Review

Quoted 1 line · Paul Durrant
(quoted diff) +0 -0

b/tools/libs/foreignmemory/libxenforeignmemory.map

tools/libs/foreignmemory/libxenforeignmemory.map VERS_1.0 { · line 9

Quoted 10 lines

index df206b3..5c9806c 100644

tools/libs/foreignmemory/libxenforeignmemory.map +1 -0
@@ -4,5 +4,6 @@ VERS_1.0 {
 		xenforeignmemory_close;
 		xenforeignmemory_map;
 		xenforeignmemory_unmap;
+		xenforeignmemory_restrict;
 	local: *; /* Do not expose anything by default */
 };

This isn't correct.

Quoted 3 lines

New functions like this need to bump at least the SO minor version, like c/s f1446de4ba

Sorry, yes, I forgot these libraries are supposed to be stable now.

Quoted 2 lines

Fixing this is a blocker to releasing 4.9

I'll submit a patch on Monday.

Quoted 3 lines

Also, we should really get automatic ABI checking built into the release process, to prevent mistakes like this from happening accidentally.

Yes, definitely.

Paul

Quoted 1 line

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
Quoted 41 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 24 March 2017 20:24
To: Andrew Cooper <[email protected]>; xen- [email protected]
Cc: Ian Jackson <[email protected]>; Julien Grall <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [Xen-devel] [PATCH] tools/libxenforeignmemory: add a call to restrict the handle

Quoted 4 lines

-----Original Message-----
From: Andrew Cooper
Sent: 24 March 2017 20:10
To: Paul Durrant <[email protected]>; xen-

[email protected]

Quoted 21 lines

Cc: Wei Liu <[email protected]>; Ian Jackson <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [Xen-devel] [PATCH] tools/libxenforeignmemory: add a call to restrict the handle

Review

Quoted 1 line · Paul Durrant
(quoted diff) +0 -0

b/tools/libs/foreignmemory/libxenforeignmemory.map

tools/libs/foreignmemory/libxenforeignmemory.map VERS_1.0 { · line 9

Quoted 10 lines

index df206b3..5c9806c 100644

tools/libs/foreignmemory/libxenforeignmemory.map +1 -0
@@ -4,5 +4,6 @@ VERS_1.0 {
 		xenforeignmemory_close;
 		xenforeignmemory_map;
 		xenforeignmemory_unmap;
+		xenforeignmemory_restrict;
 	local: *; /* Do not expose anything by default */
 };

This isn't correct.

Quoted 3 lines

New functions like this need to bump at least the SO minor version, like c/s f1446de4ba

Quoted 6 lines

Sorry, yes, I forgot these libraries are supposed to be stable now.

Quoted 2 lines

Fixing this is a blocker to releasing 4.9

I'll submit a patch on Monday.

Actually, on second thoughts, do we want to bump the version for all changes or just incompatible ones? I added a call here so it shouldn't break any older application compiling against this library.

Paul

Quoted 7 lines
Quoted 4 lines

Also, we should really get automatic ABI checking built into the release process, to prevent mistakes like this from happening accidentally.

Yes, definitely.

Quoted 7 lines

Paul

Quoted 1 line

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
Quoted 39 lines · Paul Durrant
Quoted 39 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 24 March 2017 20:24
To: Andrew Cooper <[email protected]>; xen- [email protected]
Cc: Ian Jackson <[email protected]>; Julien Grall <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [Xen-devel] [PATCH] tools/libxenforeignmemory: add a call to restrict the handle

Quoted 4 lines

-----Original Message-----
From: Andrew Cooper
Sent: 24 March 2017 20:10
To: Paul Durrant <[email protected]>; xen-

[email protected]

Quoted 23 lines

Cc: Wei Liu <[email protected]>; Ian Jackson <[email protected]>; Julien Grall <[email protected]>
Subject: Re: [Xen-devel] [PATCH] tools/libxenforeignmemory: add a call to restrict the handle

Review

Quoted 1 line · Paul Durrant
(quoted diff) +0 -0

b/tools/libs/foreignmemory/libxenforeignmemory.map

tools/libs/foreignmemory/libxenforeignmemory.map VERS_1.0 { · line 9

Quoted 10 lines

index df206b3..5c9806c 100644

tools/libs/foreignmemory/libxenforeignmemory.map +1 -0
@@ -4,5 +4,6 @@ VERS_1.0 {
 		xenforeignmemory_close;
 		xenforeignmemory_map;
 		xenforeignmemory_unmap;
+		xenforeignmemory_restrict;
 	local: *; /* Do not expose anything by default */
 };

This isn't correct.

New functions like this need to bump at least the SO minor version, like c/s f1446de4ba

Quoted 6 lines
Quoted 5 lines

Sorry, yes, I forgot these libraries are supposed to be stable now.

Quoted 2 lines

Fixing this is a blocker to releasing 4.9

I'll submit a patch on Monday.

Actually, on second thoughts, do we want to bump the version for all changes or just incompatible ones? I added a call here so it shouldn't break any older application compiling against this library.

You must bump the versions; the version information gets embedded as part of the dynamic linkage of the application built against libxenforeignmemory.

In particular, you need to prevent an application built now from referencing [email protected] because the version 1.0 shipped in all earlier versions of Xen lacked this function.

Not bumping the version now will result in newer applications being built which the dynamic loader thinks will work with older versions of the library, rather than correctly identifying that a newer version of the library is required.

As with other things in staging, it can get away with only being bumped once per Xen release, but it must always be bumped at the first change.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw
Quoted 70 lines

-----Original Message-----
From: Andrew Cooper [mailto:[email protected]] On Behalf Of Andrew Cooper
Sent: 27 March 2017 09:16
To: Paul Durrant <[email protected]>; [email protected]
Cc: Ian Jackson <[email protected]>; Julien Grall <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [Xen-devel] [PATCH] tools/libxenforeignmemory: add a call to restrict the handle

Quoted 9 lines · Paul Durrant
Quoted 9 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 24 March 2017 20:24
To: Andrew Cooper <[email protected]>; xen- [email protected]
Cc: Ian Jackson <[email protected]>; Julien Grall <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [Xen-devel] [PATCH] tools/libxenforeignmemory: add a call

to

Quoted 8 lines
Quoted 8 lines

restrict the handle

Quoted 4 lines

-----Original Message-----
From: Andrew Cooper
Sent: 24 March 2017 20:10
To: Paul Durrant <[email protected]>; xen-

[email protected]

Quoted 1 line
Cc Wei Liu <[email protected]>; Ian Jackson

<[email protected]>;

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Julien Grall <[email protected]>
Subject: Re: [Xen-devel] [PATCH] tools/libxenforeignmemory: add a call

to

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

restrict the handle

Review

Quoted 1 line · Paul Durrant
(quoted diff) +0 -0

b/tools/libs/foreignmemory/libxenforeignmemory.map

tools/libs/foreignmemory/libxenforeignmemory.map VERS_1.0 { · line 9

Quoted 10 lines

index df206b3..5c9806c 100644

tools/libs/foreignmemory/libxenforeignmemory.map +1 -0
@@ -4,5 +4,6 @@ VERS_1.0 {
 		xenforeignmemory_close;
 		xenforeignmemory_map;
 		xenforeignmemory_unmap;
+		xenforeignmemory_restrict;
 	local: *; /* Do not expose anything by default */
 };

This isn't correct.

New functions like this need to bump at least the SO minor version, like c/s f1446de4ba

Quoted 6 lines
Quoted 5 lines

Sorry, yes, I forgot these libraries are supposed to be stable now.

Quoted 2 lines

Fixing this is a blocker to releasing 4.9

I'll submit a patch on Monday.

Actually, on second thoughts, do we want to bump the version for all

changes or just incompatible ones? I added a call here so it shouldn't break any older application compiling against this library.

You must bump the versions; the version information gets embedded as part of the dynamic linkage of the application built against libxenforeignmemory.

In particular, you need to prevent an application built now from referencing [email protected] because the version 1.0 shipped in all earlier versions of Xen lacked this function.

Quoted 8 lines

Not bumping the version now will result in newer applications being built which the dynamic loader thinks will work with older versions of the library, rather than correctly identifying that a newer version of the library is required.

As with other things in staging, it can get away with only being bumped once per Xen release, but it must always be bumped at the first change.

Ok. I'll send a patch today then.

Paul

Quoted 1 line

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw
In reply to Andrew Cooper

Hi Andre,

Quoted 15 lines · Andrew Cooper

tools/libs/foreignmemory/libxenforeignmemory.map VERS_1.0 { · line 9

Quoted 11 lines · Paul Durrant
tools/libs/foreignmemory/libxenforeignmemory.map +1 -0
index df206b3..5c9806c 100644
@@ -4,5 +4,6 @@ VERS_1.0 {
 		xenforeignmemory_close;
 		xenforeignmemory_map;
 		xenforeignmemory_unmap;
+		xenforeignmemory_restrict;
 	local: *; /* Do not expose anything by default */
 };

This isn't correct.

Quoted 4 lines

New functions like this need to bump at least the SO minor version, like c/s f1446de4ba

Fixing this is a blocker to releasing 4.9

I saw a patch (commit 9a7fbdd692) merged today to fix this. Let me know if there are more patches coming to address this.

Quoted 3 lines

Also, we should really get automatic ABI checking built into the release process, to prevent mistakes like this from happening accidentally.

That's a good idea. I will create a task on Jira for that.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#8 lore raw
Quoted 19 lines · Julien Grall

Hi Andre,

Quoted 16 lines · Andrew Cooper

tools/libs/foreignmemory/libxenforeignmemory.map VERS_1.0 { · line 9

Quoted 12 lines · Paul Durrant
tools/libs/foreignmemory/libxenforeignmemory.map +1 -0
index df206b3..5c9806c 100644
@@ -4,5 +4,6 @@ VERS_1.0 {
         xenforeignmemory_close;
         xenforeignmemory_map;
         xenforeignmemory_unmap;
+        xenforeignmemory_restrict;
     local: *; /* Do not expose anything by default */
 };

This isn't correct.

Quoted 7 lines
Quoted 4 lines

New functions like this need to bump at least the SO minor version, like c/s f1446de4ba

Fixing this is a blocker to releasing 4.9

I saw a patch (commit 9a7fbdd692) merged today to fix this. Let me know if there are more patches coming to address this.

That should be all to fix this specific issue.

Quoted 6 lines
Quoted 4 lines

Also, we should really get automatic ABI checking built into the release process, to prevent mistakes like this from happening accidentally.

That's a good idea. I will create a task on Jira for that.

https://xenproject.atlassian.net/projects/XEN/issues/XEN-33 is way ahead of you :)

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel