Be informed when a specific vdso is run











up vote
2
down vote

favorite












I'm currently trying to implement my own VDSO. I have used this tutorial which explains how to do this for a 2.6 kernel.



I tested it and I got this working. (I succeeded in creating a kernel variable and accessing it from userland.)



Is there a way to be know in the kernel when the vdso has been called? I assume this can't be done synchronously (as the vdso is handled in userland). But is there any possibility (even dirty) from the kernel to know whether the function has been called (maybe with a hardware breakpoint or something)?



What I’d like to do is something like the function my_vdso_has_been_called()) in this code:



void update_vsyscall(/* […] */) {
// […]
if(my_vdso_has_been_called())
do_something();
}


Note: the function update_vsyscall can be found in arch/x86/kernel/vsyscall_64.c










share|improve this question













migrated from unix.stackexchange.com Nov 22 at 20:02


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.















  • can something like SystemTap react to your __vdso_myvdso being called?
    – thrig
    Nov 22 at 14:20










  • If I understand well, SystemTap is a tool only called from outside the kernel. So unless there is an equivalent tool running in kernelmode, I don’t think so. But correct me if I'm wrong.
    – Maxime B.
    Nov 22 at 16:43










  • SystemTap compiles code into the kernel.
    – thrig
    Nov 22 at 17:44















up vote
2
down vote

favorite












I'm currently trying to implement my own VDSO. I have used this tutorial which explains how to do this for a 2.6 kernel.



I tested it and I got this working. (I succeeded in creating a kernel variable and accessing it from userland.)



Is there a way to be know in the kernel when the vdso has been called? I assume this can't be done synchronously (as the vdso is handled in userland). But is there any possibility (even dirty) from the kernel to know whether the function has been called (maybe with a hardware breakpoint or something)?



What I’d like to do is something like the function my_vdso_has_been_called()) in this code:



void update_vsyscall(/* […] */) {
// […]
if(my_vdso_has_been_called())
do_something();
}


Note: the function update_vsyscall can be found in arch/x86/kernel/vsyscall_64.c










share|improve this question













migrated from unix.stackexchange.com Nov 22 at 20:02


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.















  • can something like SystemTap react to your __vdso_myvdso being called?
    – thrig
    Nov 22 at 14:20










  • If I understand well, SystemTap is a tool only called from outside the kernel. So unless there is an equivalent tool running in kernelmode, I don’t think so. But correct me if I'm wrong.
    – Maxime B.
    Nov 22 at 16:43










  • SystemTap compiles code into the kernel.
    – thrig
    Nov 22 at 17:44













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm currently trying to implement my own VDSO. I have used this tutorial which explains how to do this for a 2.6 kernel.



I tested it and I got this working. (I succeeded in creating a kernel variable and accessing it from userland.)



Is there a way to be know in the kernel when the vdso has been called? I assume this can't be done synchronously (as the vdso is handled in userland). But is there any possibility (even dirty) from the kernel to know whether the function has been called (maybe with a hardware breakpoint or something)?



What I’d like to do is something like the function my_vdso_has_been_called()) in this code:



void update_vsyscall(/* […] */) {
// […]
if(my_vdso_has_been_called())
do_something();
}


Note: the function update_vsyscall can be found in arch/x86/kernel/vsyscall_64.c










share|improve this question













I'm currently trying to implement my own VDSO. I have used this tutorial which explains how to do this for a 2.6 kernel.



I tested it and I got this working. (I succeeded in creating a kernel variable and accessing it from userland.)



Is there a way to be know in the kernel when the vdso has been called? I assume this can't be done synchronously (as the vdso is handled in userland). But is there any possibility (even dirty) from the kernel to know whether the function has been called (maybe with a hardware breakpoint or something)?



What I’d like to do is something like the function my_vdso_has_been_called()) in this code:



void update_vsyscall(/* […] */) {
// […]
if(my_vdso_has_been_called())
do_something();
}


Note: the function update_vsyscall can be found in arch/x86/kernel/vsyscall_64.c







linux kernel linux-kernel system-calls






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 17:15









Maxime B.

324




324




migrated from unix.stackexchange.com Nov 22 at 20:02


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.






migrated from unix.stackexchange.com Nov 22 at 20:02


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.














  • can something like SystemTap react to your __vdso_myvdso being called?
    – thrig
    Nov 22 at 14:20










  • If I understand well, SystemTap is a tool only called from outside the kernel. So unless there is an equivalent tool running in kernelmode, I don’t think so. But correct me if I'm wrong.
    – Maxime B.
    Nov 22 at 16:43










  • SystemTap compiles code into the kernel.
    – thrig
    Nov 22 at 17:44


















  • can something like SystemTap react to your __vdso_myvdso being called?
    – thrig
    Nov 22 at 14:20










  • If I understand well, SystemTap is a tool only called from outside the kernel. So unless there is an equivalent tool running in kernelmode, I don’t think so. But correct me if I'm wrong.
    – Maxime B.
    Nov 22 at 16:43










  • SystemTap compiles code into the kernel.
    – thrig
    Nov 22 at 17:44
















can something like SystemTap react to your __vdso_myvdso being called?
– thrig
Nov 22 at 14:20




can something like SystemTap react to your __vdso_myvdso being called?
– thrig
Nov 22 at 14:20












If I understand well, SystemTap is a tool only called from outside the kernel. So unless there is an equivalent tool running in kernelmode, I don’t think so. But correct me if I'm wrong.
– Maxime B.
Nov 22 at 16:43




If I understand well, SystemTap is a tool only called from outside the kernel. So unless there is an equivalent tool running in kernelmode, I don’t think so. But correct me if I'm wrong.
– Maxime B.
Nov 22 at 16:43












SystemTap compiles code into the kernel.
– thrig
Nov 22 at 17:44




SystemTap compiles code into the kernel.
– thrig
Nov 22 at 17:44












1 Answer
1






active

oldest

votes

















up vote
1
down vote













Since you know how to declare a shared variable and access it from both the kernel and the vDSO, you can use that: declare a new variable, and increment it from the vDSO whenever it’s called.






share|improve this answer





















  • In my understanding, theses shared variables are read-only from the userland. Thus, this code will compile but if I uncomment the incremenation I’m having a segfault. notrace int __vdso_myvdso(void) { // ++*vmyvar; /* The program will crash if I uncomment this*/ ` return *vmyvar;` } Am I doing it wrong? Are there other variables I can modify? Or can I disable this read-only protection?
    – Maxime B.
    Nov 22 at 9:14










  • Sorry, you’re right, VVAR only gives read-only access from the vDSO.
    – Stephen Kitt
    Nov 22 at 9:53










  • I’m trying to disable this read-only protection. Do you know how could I do that? I added the VM_WRITE flag to install_special_mapping in arch_setup_additional_pages(…) from vma.c but this is not enough (I still get a segfault when I increment my variable). Do you know what the additional adaptations are?
    – Maxime B.
    Nov 22 at 14:19











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437433%2fbe-informed-when-a-specific-vdso-is-run%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













Since you know how to declare a shared variable and access it from both the kernel and the vDSO, you can use that: declare a new variable, and increment it from the vDSO whenever it’s called.






share|improve this answer





















  • In my understanding, theses shared variables are read-only from the userland. Thus, this code will compile but if I uncomment the incremenation I’m having a segfault. notrace int __vdso_myvdso(void) { // ++*vmyvar; /* The program will crash if I uncomment this*/ ` return *vmyvar;` } Am I doing it wrong? Are there other variables I can modify? Or can I disable this read-only protection?
    – Maxime B.
    Nov 22 at 9:14










  • Sorry, you’re right, VVAR only gives read-only access from the vDSO.
    – Stephen Kitt
    Nov 22 at 9:53










  • I’m trying to disable this read-only protection. Do you know how could I do that? I added the VM_WRITE flag to install_special_mapping in arch_setup_additional_pages(…) from vma.c but this is not enough (I still get a segfault when I increment my variable). Do you know what the additional adaptations are?
    – Maxime B.
    Nov 22 at 14:19















up vote
1
down vote













Since you know how to declare a shared variable and access it from both the kernel and the vDSO, you can use that: declare a new variable, and increment it from the vDSO whenever it’s called.






share|improve this answer





















  • In my understanding, theses shared variables are read-only from the userland. Thus, this code will compile but if I uncomment the incremenation I’m having a segfault. notrace int __vdso_myvdso(void) { // ++*vmyvar; /* The program will crash if I uncomment this*/ ` return *vmyvar;` } Am I doing it wrong? Are there other variables I can modify? Or can I disable this read-only protection?
    – Maxime B.
    Nov 22 at 9:14










  • Sorry, you’re right, VVAR only gives read-only access from the vDSO.
    – Stephen Kitt
    Nov 22 at 9:53










  • I’m trying to disable this read-only protection. Do you know how could I do that? I added the VM_WRITE flag to install_special_mapping in arch_setup_additional_pages(…) from vma.c but this is not enough (I still get a segfault when I increment my variable). Do you know what the additional adaptations are?
    – Maxime B.
    Nov 22 at 14:19













up vote
1
down vote










up vote
1
down vote









Since you know how to declare a shared variable and access it from both the kernel and the vDSO, you can use that: declare a new variable, and increment it from the vDSO whenever it’s called.






share|improve this answer












Since you know how to declare a shared variable and access it from both the kernel and the vDSO, you can use that: declare a new variable, and increment it from the vDSO whenever it’s called.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 at 22:28









Stephen Kitt

1,2501020




1,2501020












  • In my understanding, theses shared variables are read-only from the userland. Thus, this code will compile but if I uncomment the incremenation I’m having a segfault. notrace int __vdso_myvdso(void) { // ++*vmyvar; /* The program will crash if I uncomment this*/ ` return *vmyvar;` } Am I doing it wrong? Are there other variables I can modify? Or can I disable this read-only protection?
    – Maxime B.
    Nov 22 at 9:14










  • Sorry, you’re right, VVAR only gives read-only access from the vDSO.
    – Stephen Kitt
    Nov 22 at 9:53










  • I’m trying to disable this read-only protection. Do you know how could I do that? I added the VM_WRITE flag to install_special_mapping in arch_setup_additional_pages(…) from vma.c but this is not enough (I still get a segfault when I increment my variable). Do you know what the additional adaptations are?
    – Maxime B.
    Nov 22 at 14:19


















  • In my understanding, theses shared variables are read-only from the userland. Thus, this code will compile but if I uncomment the incremenation I’m having a segfault. notrace int __vdso_myvdso(void) { // ++*vmyvar; /* The program will crash if I uncomment this*/ ` return *vmyvar;` } Am I doing it wrong? Are there other variables I can modify? Or can I disable this read-only protection?
    – Maxime B.
    Nov 22 at 9:14










  • Sorry, you’re right, VVAR only gives read-only access from the vDSO.
    – Stephen Kitt
    Nov 22 at 9:53










  • I’m trying to disable this read-only protection. Do you know how could I do that? I added the VM_WRITE flag to install_special_mapping in arch_setup_additional_pages(…) from vma.c but this is not enough (I still get a segfault when I increment my variable). Do you know what the additional adaptations are?
    – Maxime B.
    Nov 22 at 14:19
















In my understanding, theses shared variables are read-only from the userland. Thus, this code will compile but if I uncomment the incremenation I’m having a segfault. notrace int __vdso_myvdso(void) { // ++*vmyvar; /* The program will crash if I uncomment this*/ ` return *vmyvar;` } Am I doing it wrong? Are there other variables I can modify? Or can I disable this read-only protection?
– Maxime B.
Nov 22 at 9:14




In my understanding, theses shared variables are read-only from the userland. Thus, this code will compile but if I uncomment the incremenation I’m having a segfault. notrace int __vdso_myvdso(void) { // ++*vmyvar; /* The program will crash if I uncomment this*/ ` return *vmyvar;` } Am I doing it wrong? Are there other variables I can modify? Or can I disable this read-only protection?
– Maxime B.
Nov 22 at 9:14












Sorry, you’re right, VVAR only gives read-only access from the vDSO.
– Stephen Kitt
Nov 22 at 9:53




Sorry, you’re right, VVAR only gives read-only access from the vDSO.
– Stephen Kitt
Nov 22 at 9:53












I’m trying to disable this read-only protection. Do you know how could I do that? I added the VM_WRITE flag to install_special_mapping in arch_setup_additional_pages(…) from vma.c but this is not enough (I still get a segfault when I increment my variable). Do you know what the additional adaptations are?
– Maxime B.
Nov 22 at 14:19




I’m trying to disable this read-only protection. Do you know how could I do that? I added the VM_WRITE flag to install_special_mapping in arch_setup_additional_pages(…) from vma.c but this is not enough (I still get a segfault when I increment my variable). Do you know what the additional adaptations are?
– Maxime B.
Nov 22 at 14:19


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437433%2fbe-informed-when-a-specific-vdso-is-run%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Morgemoulin

Scott Moir

Souastre