"current" in kernel is a global macro, that always point to the "struct task_struct * " of the currently executing task (for details on task_struct, ref Robert Love, pg 24-27). Now I have a macro called push root which has the following purpose- "to push root user and group to current context so to set current uid and gid to 0." Now in kernel 3.8.3, I would do something like struct cred *new1; new1 =prepare_creds(); new1->uid = 0; new1->gid = 0; commit_creds(new1); So macro definition of push root, according to what I have proposed above, should be #define push_root \ new1 =prepare_creds(); \ new1->uid = 0; \ new1->gid = 0; \ commit_creds(new1) But I am getting errors like multiple declaration of new1 etc. Even if I declare prepare_creds outside macro definition like new1 =prepare_creds(); #define push_root \ new1->uid = 0; \ new1->gid = 0; \ commit_creds(new1) I think I am facing the issue that the macros are inlined during compilation, so when the compiler wants to replace them, it raises issues. I could think of two ways to solve this issue- 1. define a new macro like #define prep_root() which defines the var once for all, and that I have to put it at the begin of each function needing push_root. This is not a very good method. 2. I should still try to go with inlined functions but how ? Can someone suggest anything Regards, Saket Sinha
A small suggestion, use begin { and end } braces for declaring your macro. May be I am wrong, but you can try this. Then, the declaration become local to that block. Regards, Srinivas On Mon, Jul 15, 2013 at 1:03 AM, Saket Sinha <saket.sinha89@gmail.com>wrote:
"current" in kernel is a global macro, that always point to the "struct task_struct * " of the currently executing task (for details on task_struct, ref Robert Love, pg 24-27).
Now I have a macro called push root which has the following purpose- "to push root user and group to current context so to set current uid and gid to 0."
Now in kernel 3.8.3, I would do something like
struct cred *new1; new1 =prepare_creds(); new1->uid = 0; new1->gid = 0; commit_creds(new1);
So macro definition of push root, according to what I have proposed above, should be #define push_root \ new1 =prepare_creds(); \ new1->uid = 0; \ new1->gid = 0; \ commit_creds(new1)
But I am getting errors like multiple declaration of new1 etc.
Even if I declare prepare_creds outside macro definition like
new1 =prepare_creds(); #define push_root \ new1->uid = 0; \ new1->gid = 0; \ commit_creds(new1)
I think I am facing the issue that the macros are inlined during compilation, so when the compiler wants to replace them, it raises issues.
I could think of two ways to solve this issue-
1. define a new macro like #define prep_root() which defines the var once for all, and that I have to put it at the begin of each function needing push_root. This is not a very good method.
2. I should still try to go with inlined functions but how ?
Can someone suggest anything
Regards, Saket Sinha
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Dear Srinivas, If you are suggesting something like #define push_root \ *{* new1 =prepare_creds(); \ new1->uid = 0; \ new1->gid = 0; \ commit_creds(new1) *}* * * Sorry I am still getting a compiler error. Regards, Saket Sinha * * On Mon, Jul 15, 2013 at 2:25 PM, Srinivas Ganji < srinivasganji.kernel@gmail.com> wrote:
A small suggestion, use begin { and end } braces for declaring your macro. May be I am wrong, but you can try this. Then, the declaration become local to that block.
Regards, Srinivas
On Mon, Jul 15, 2013 at 1:03 AM, Saket Sinha <saket.sinha89@gmail.com>wrote:
"current" in kernel is a global macro, that always point to the "struct task_struct * " of the currently executing task (for details on task_struct, ref Robert Love, pg 24-27).
Now I have a macro called push root which has the following purpose- "to push root user and group to current context so to set current uid and gid to 0."
Now in kernel 3.8.3, I would do something like
struct cred *new1; new1 =prepare_creds(); new1->uid = 0; new1->gid = 0; commit_creds(new1);
So macro definition of push root, according to what I have proposed above, should be #define push_root \ new1 =prepare_creds(); \ new1->uid = 0; \ new1->gid = 0; \ commit_creds(new1)
But I am getting errors like multiple declaration of new1 etc.
Even if I declare prepare_creds outside macro definition like
new1 =prepare_creds(); #define push_root \ new1->uid = 0; \ new1->gid = 0; \ commit_creds(new1)
I think I am facing the issue that the macros are inlined during compilation, so when the compiler wants to replace them, it raises issues.
I could think of two ways to solve this issue-
1. define a new macro like #define prep_root() which defines the var once for all, and that I have to put it at the begin of each function needing push_root. This is not a very good method.
2. I should still try to go with inlined functions but how ?
Can someone suggest anything
Regards, Saket Sinha
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
On Mon, Jul 15, 2013 at 3:54 PM, Saket Sinha <saket.sinha89@gmail.com>wrote:
Dear Srinivas,
If you are suggesting something like
#define push_root \ *{* new1 =prepare_creds(); \ new1->uid = 0; \ new1->gid = 0; \ commit_creds(new1) *}* * * Sorry I am still getting a compiler error.
What errors is the compiler giving? Last time you mentioned that it's saying new1 has multiple def's. Is it possible your macro has a declaration of new1 in it. So if you use the macro in the same scope, you'll get re-def errors. You can also try and look at the intermediate file for your source code, i.e after the pre-processing is done (*.i files). I don't remember the exact gcc option. Try --save-temps and look at the <source file name>.i file. HTH, -mandeep
Regards, Saket Sinha * *
On Mon, Jul 15, 2013 at 2:25 PM, Srinivas Ganji < srinivasganji.kernel@gmail.com> wrote:
A small suggestion, use begin { and end } braces for declaring your macro. May be I am wrong, but you can try this. Then, the declaration become local to that block.
Regards, Srinivas
On Mon, Jul 15, 2013 at 1:03 AM, Saket Sinha <saket.sinha89@gmail.com>wrote:
"current" in kernel is a global macro, that always point to the "struct task_struct * " of the currently executing task (for details on task_struct, ref Robert Love, pg 24-27).
Now I have a macro called push root which has the following purpose- "to push root user and group to current context so to set current uid and gid to 0."
Now in kernel 3.8.3, I would do something like
struct cred *new1; new1 =prepare_creds(); new1->uid = 0; new1->gid = 0; commit_creds(new1);
So macro definition of push root, according to what I have proposed above, should be #define push_root \ new1 =prepare_creds(); \ new1->uid = 0; \ new1->gid = 0; \ commit_creds(new1)
But I am getting errors like multiple declaration of new1 etc.
Even if I declare prepare_creds outside macro definition like
new1 =prepare_creds(); #define push_root \ new1->uid = 0; \ new1->gid = 0; \ commit_creds(new1)
I think I am facing the issue that the macros are inlined during compilation, so when the compiler wants to replace them, it raises issues.
I could think of two ways to solve this issue-
1. define a new macro like #define prep_root() which defines the var once for all, and that I have to put it at the begin of each function needing push_root. This is not a very good method.
2. I should still try to go with inlined functions but how ?
Can someone suggest anything
Regards, Saket Sinha
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Mandip: Error is expected error or declaration at the end of input Anish: that '\' should not be there first of all and even if I put it same error
On Mon, Jul 15, 2013 at 4:50 PM, Saket Sinha <saket.sinha89@gmail.com>wrote:
Mandip: Error is expected error or declaration at the end of input
Without looking at the code, it's difficult to comment further. Can you attach a small compilable example which exhibits the error? -mandeep
Anish: that '\' should not be there first of all and even if I put it same error
Here is the macro https://github.com/HeisSpiter/hepunion/blob/master/fs/hepunion/hepunion.h#L3... Now this driver is at 2.6.18 kernel. I have to upgrade it to 3.8.3. As I have said "current" in kernel is a global macro, that always point to the "struct task_struct * " of the currently executing task (for details on task_struct, ref Robert Love, pg 24-27). https://github.com/HeisSpiter/hepunion/blob/master/fs/hepunion/hepunion.h#L3... Now if you look at thse two lines- current->fsuid = 0; \ current->fsgid = 0 Now task struct does not contain fsuid and fsgid, instead you have struct cred containing fsuid and fsgid. http://lxr.free-electrons.com/source/include/linux/cred.h#L102 So normal method is struct cred *new1; new1 =prepare_creds(); //make changes to any member of this structure commit_creds(new1); Now this above action I need to perform through a macro, in order to bring minimal changes to the driver. Now, I have told everything. Can someone suggest something that might work. Regards, Saket Sinha On Mon, Jul 15, 2013 at 5:07 PM, Mandeep Sandhu <mandeepsandhu.chd@gmail.com
wrote:
On Mon, Jul 15, 2013 at 4:50 PM, Saket Sinha <saket.sinha89@gmail.com>wrote:
Mandip: Error is expected error or declaration at the end of input
Without looking at the code, it's difficult to comment further.
Can you attach a small compilable example which exhibits the error?
-mandeep
Anish: that '\' should not be there first of all and even if I put it same error
How about: #define push_root() \ recursive_mutex_lock(&context->id_lock); \ context->uid = current->fsuid; \ context->gid = current->fsgid; \ do { \ struct cred *new1 = prepare_creds(); \ //make changes to any member of this structure \ commit_creds(new1); \ } while(0); HTH, -mandeep On Mon, Jul 15, 2013 at 5:27 PM, Saket Sinha <saket.sinha89@gmail.com>wrote:
Here is the macro
https://github.com/HeisSpiter/hepunion/blob/master/fs/hepunion/hepunion.h#L3...
Now this driver is at 2.6.18 kernel. I have to upgrade it to 3.8.3. As I have said "current" in kernel is a global macro, that always point to the "struct task_struct * " of the currently executing task (for details on task_struct, ref Robert Love, pg 24-27).
https://github.com/HeisSpiter/hepunion/blob/master/fs/hepunion/hepunion.h#L3...
Now if you look at thse two lines-
current->fsuid = 0; \ current->fsgid = 0
Now task struct does not contain fsuid and fsgid, instead you have struct cred containing fsuid and fsgid. http://lxr.free-electrons.com/source/include/linux/cred.h#L102
So normal method is struct cred *new1; new1 =prepare_creds(); //make changes to any member of this structure commit_creds(new1);
Now this above action I need to perform through a macro, in order to bring minimal changes to the driver.
Now, I have told everything. Can someone suggest something that might work.
Regards, Saket Sinha
On Mon, Jul 15, 2013 at 5:07 PM, Mandeep Sandhu < mandeepsandhu.chd@gmail.com> wrote:
On Mon, Jul 15, 2013 at 4:50 PM, Saket Sinha <saket.sinha89@gmail.com>wrote:
Mandip: Error is expected error or declaration at the end of input
Without looking at the code, it's difficult to comment further.
Can you attach a small compilable example which exhibits the error?
-mandeep
Anish: that '\' should not be there first of all and even if I put it same error
Mandeep: Even this hasnt helped..though it was a btight idea. :( P.S.-I can give my system on remote via Team Viewer, if you want to try. Regards, Saket Sinha On Mon, Jul 15, 2013 at 5:39 PM, Mandeep Sandhu <mandeepsandhu.chd@gmail.com
wrote:
How about:
#define push_root() \ recursive_mutex_lock(&context->id_lock); \ context->uid = current->fsuid; \ context->gid = current->fsgid; \ do { \ struct cred *new1 = prepare_creds(); \ //make changes to any member of this structure \
commit_creds(new1); \ } while(0);
HTH,
-mandeep
On Mon, Jul 15, 2013 at 5:27 PM, Saket Sinha <saket.sinha89@gmail.com>wrote:
Here is the macro
https://github.com/HeisSpiter/hepunion/blob/master/fs/hepunion/hepunion.h#L3...
Now this driver is at 2.6.18 kernel. I have to upgrade it to 3.8.3. As I have said "current" in kernel is a global macro, that always point to the "struct task_struct * " of the currently executing task (for details on task_struct, ref Robert Love, pg 24-27).
https://github.com/HeisSpiter/hepunion/blob/master/fs/hepunion/hepunion.h#L3...
Now if you look at thse two lines-
current->fsuid = 0; \ current->fsgid = 0
Now task struct does not contain fsuid and fsgid, instead you have struct cred containing fsuid and fsgid. http://lxr.free-electrons.com/source/include/linux/cred.h#L102
So normal method is struct cred *new1; new1 =prepare_creds(); //make changes to any member of this structure commit_creds(new1);
Now this above action I need to perform through a macro, in order to bring minimal changes to the driver.
Now, I have told everything. Can someone suggest something that might work.
Regards, Saket Sinha
On Mon, Jul 15, 2013 at 5:07 PM, Mandeep Sandhu < mandeepsandhu.chd@gmail.com> wrote:
On Mon, Jul 15, 2013 at 4:50 PM, Saket Sinha <saket.sinha89@gmail.com>wrote:
Mandip: Error is expected error or declaration at the end of input
Without looking at the code, it's difficult to comment further.
Can you attach a small compilable example which exhibits the error?
-mandeep
Anish: that '\' should not be there first of all and even if I put it same error
On Mon, 15 Jul 2013 17:39:15 +0530, Mandeep Sandhu said:
#define push_root() \ recursive_mutex_lock(&context->id_lock); \ context->uid = current->fsuid; \ context->gid = current->fsgid; \ do { \ struct cred *new1 = prepare_creds(); \ //make changes to any member of this structure \ commit_creds(new1); \ } while(0);
Actually, this has 3 problems: 1) You have a call to mutex_loc() that doesn't get unlocked. This Is Bad. 2) If you're using the 'do { foo } while (0)' trick, you want to put the *whole thing* inside the { } (Hint - you can put local variable definitions inside the curlies as well). 3) Leave the ; off the 'while (0)' in the macro definition, because:
int main() { printf("in main\n"); pushme return 0; }
Somebody will forget and put a ; after pushme - and in some contexts, the additional ; will then cause issues.
Russel: Thank you a curly bracket was missing. How could I not notice. Valdis: I shall take your suggestions. Mandeep: Thank you for that enlighting ideas Regards, Saket Sinha On Mon, Jul 15, 2013 at 7:52 PM, <Valdis.Kletnieks@vt.edu> wrote:
On Mon, 15 Jul 2013 17:39:15 +0530, Mandeep Sandhu said:
#define push_root() \ recursive_mutex_lock(&context->id_lock); \ context->uid = current->fsuid; \ context->gid = current->fsgid; \ do { \ struct cred *new1 = prepare_creds(); \ //make changes to any member of this structure \ commit_creds(new1); \ } while(0);
Actually, this has 3 problems:
1) You have a call to mutex_loc() that doesn't get unlocked. This Is Bad.
2) If you're using the 'do { foo } while (0)' trick, you want to put the *whole thing* inside the { } (Hint - you can put local variable definitions inside the curlies as well).
3) Leave the ; off the 'while (0)' in the macro definition, because:
int main() { printf("in main\n"); pushme return 0; }
Somebody will forget and put a ; after pushme - and in some contexts, the additional ; will then cause issues.
BTW....I forgot to mention the problem got solved. Thanks to your suggestions. Regards, Saket Sinha On Mon, Jul 15, 2013 at 9:38 PM, Saket Sinha <saket.sinha89@gmail.com>wrote:
Russel: Thank you a curly bracket was missing. How could I not notice. Valdis: I shall take your suggestions. Mandeep: Thank you for that enlighting ideas
Regards, Saket Sinha
On Mon, Jul 15, 2013 at 7:52 PM, <Valdis.Kletnieks@vt.edu> wrote:
On Mon, 15 Jul 2013 17:39:15 +0530, Mandeep Sandhu said:
#define push_root() \ recursive_mutex_lock(&context->id_lock); \ context->uid = current->fsuid; \ context->gid = current->fsgid; \ do { \ struct cred *new1 = prepare_creds(); \ //make changes to any member of this structure \ commit_creds(new1); \ } while(0);
Actually, this has 3 problems:
1) You have a call to mutex_loc() that doesn't get unlocked. This Is Bad.
2) If you're using the 'do { foo } while (0)' trick, you want to put the *whole thing* inside the { } (Hint - you can put local variable definitions inside the curlies as well).
3) Leave the ; off the 'while (0)' in the macro definition, because:
int main() { printf("in main\n"); pushme return 0; }
Somebody will forget and put a ; after pushme - and in some contexts, the additional ; will then cause issues.
Hi Sinha, I think, you can put begin { before \ but not after \ Regards, Srinivas On Mon, Jul 15, 2013 at 3:54 PM, Saket Sinha <saket.sinha89@gmail.com>wrote:
Dear Srinivas,
If you are suggesting something like
#define push_root \ *{* new1 =prepare_creds(); \ new1->uid = 0; \ new1->gid = 0; \ commit_creds(new1) *}* * * Sorry I am still getting a compiler error.
Regards, Saket Sinha * *
On Mon, Jul 15, 2013 at 2:25 PM, Srinivas Ganji < srinivasganji.kernel@gmail.com> wrote:
A small suggestion, use begin { and end } braces for declaring your macro. May be I am wrong, but you can try this. Then, the declaration become local to that block.
Regards, Srinivas
On Mon, Jul 15, 2013 at 1:03 AM, Saket Sinha <saket.sinha89@gmail.com>wrote:
"current" in kernel is a global macro, that always point to the "struct task_struct * " of the currently executing task (for details on task_struct, ref Robert Love, pg 24-27).
Now I have a macro called push root which has the following purpose- "to push root user and group to current context so to set current uid and gid to 0."
Now in kernel 3.8.3, I would do something like
struct cred *new1; new1 =prepare_creds(); new1->uid = 0; new1->gid = 0; commit_creds(new1);
So macro definition of push root, according to what I have proposed above, should be #define push_root \ new1 =prepare_creds(); \ new1->uid = 0; \ new1->gid = 0; \ commit_creds(new1)
But I am getting errors like multiple declaration of new1 etc.
Even if I declare prepare_creds outside macro definition like
new1 =prepare_creds(); #define push_root \ new1->uid = 0; \ new1->gid = 0; \ commit_creds(new1)
I think I am facing the issue that the macros are inlined during compilation, so when the compiler wants to replace them, it raises issues.
I could think of two ways to solve this issue-
1. define a new macro like #define prep_root() which defines the var once for all, and that I have to put it at the begin of each function needing push_root. This is not a very good method.
2. I should still try to go with inlined functions but how ?
Can someone suggest anything
Regards, Saket Sinha
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
participants (4)
-
Mandeep Sandhu -
Saket Sinha -
Srinivas Ganji -
Valdis.Kletnieks@vt.edu