kprobes: be more permissive when user specifies both symbol name and address
Subsystems (2)
PATCH RESEND 1/1 kprobes: be more permissive when user specifies both symbol name and address
Hi, I found that this patch wasn't merged into mainline during this merge window(maybe it wasn't cooked in any tree), while it has been acked-by for a couple of days.
Ingo, would you mind queueing this one? Thanks.
-----<8-----
Currently, if user specifies both symbol name and address, we just bail out.
This might be too rude. This patch makes it give more tolerance. If both are specified, check address first, if the symbol found does not match the one user specify, print a waring. If not found, return -ENOENT, because some symbols might have muplitple instances, we don't bother to check symbol name.
--- Documentation/kprobes.txt | 4 +++- kernel/kprobes.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-)
Documentation/kprobes.txt +3 -1
@@ -358,7 +358,9 @@ to install a probepoint is known. This field is used to calculate the probepoint. 3. Specify either the kprobe "symbol_name" OR the "addr". If both are -specified, kprobe registration will fail with -EINVAL. +specified, only check "addr", because some symbols might have muplitple +instances. If neither is specified, kprobe registration will fail +with -EINVAL. 4. With CISC architectures (such as i386 and x86_64), the kprobes code does not validate if the kprobe.addr is at an instruction boundary.
kernel/kprobes.c +29 -3
@@ -1358,15 +1358,41 @@ static bool within_kprobe_blacklist(unsigned long addr)static kprobe_opcode_t *kprobe_addr (struct kprobe *p) {kprobe_opcode_t *addr = p->addr; +char namebuf[KSYM_NAME_LEN ]; +const char *sym_name =NULL ; +unsigned long offset; -if ((p->symbol_name && p->addr) || - (!p->symbol_name && !p->addr)) +if (!p->symbol_name && !p->addr) goto invalid; -if (p->symbol_name) { +/* +* Some symbols might have muplitple instances, +* so if both specified, only check address. +*/ +if (unlikely (p->addr && p->symbol_name)) { + sym_name =kallsyms_lookup ((unsigned long )(p->addr), +NULL , &offset,NULL , namebuf); +if (!sym_name) +return ERR_PTR (-ENOENT ); + +if (strncmp (sym_name, p->symbol_name,KSYM_NAME_LEN ) + || offset != p->offset) { +pr_err ("Incorrect symbol or offset, should be " +"symbol=%s, offset=%ld.\n" , sym_name, offset); + goto invalid; + } + }else if (p->symbol_name) { +/* Only symbol case */ kprobe_lookup_name (p->symbol_name, addr);if (!addr)return ERR_PTR (-ENOENT ); + }else { +/* +* Only address case. +* Since we later will do sanity check of the +* address range in check_kprobe_address_safe(), +* do nothing here. +*/ } addr = (kprobe_opcode_t *)(((char *)addr) + p->offset);
Signature · 1 line
2.0.0
Quoted 5 lines · Jianyu Zhan
Hi, I found that this patch wasn't merged into mainline during this merge window(maybe it wasn't cooked in any tree), while it has been acked-by for a couple of days.
Ingo, would you mind queueing this one? Thanks.
Ping? I've already acked this.
Quoted 84 lines
-----<8-----
Currently, if user specifies both symbol name and address, we just bail out.
This might be too rude. This patch makes it give more tolerance. If both are specified, check address first, if the symbol found does not match the one user specify, print a waring. If not found, return
-ENOENT, because some symbols might have muplitple instances, we don't bother to check symbol name.Acked-by Masami Hiramatsu <[email protected]>Signed-off-by Jianyu Zhan <[email protected]>--- Documentation/kprobes.txt | 4 +++- kernel/kprobes.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-)Documentation/kprobes.txt +3
-1@@ -358,7 +358,9 @@ to install a probepoint is known. This field is used to calculate the probepoint. 3. Specify either the kprobe "symbol_name" OR the "addr". If both are -specified, kprobe registration will fail with -EINVAL. +specified, only check "addr", because some symbols might have muplitple +instances. If neither is specified, kprobe registration will fail +with -EINVAL. 4. With CISC architectures (such as i386 and x86_64), the kprobes code does not validate if the kprobe.addr is at an instruction boundary.kernel/kprobes.c +29
-3@@ -1358,15 +1358,41 @@ static bool within_kprobe_blacklist(unsigned long addr)static kprobe_opcode_t *kprobe_addr (struct kprobe *p) {kprobe_opcode_t *addr = p->addr; +char namebuf[KSYM_NAME_LEN ]; +const char *sym_name =NULL ; +unsigned long offset; -if ((p->symbol_name && p->addr) || - (!p->symbol_name && !p->addr)) +if (!p->symbol_name && !p->addr) goto invalid; -if (p->symbol_name) { +/* +* Some symbols might have muplitple instances, +* so if both specified, only check address. +*/ +if (unlikely (p->addr && p->symbol_name)) { + sym_name =kallsyms_lookup ((unsigned long )(p->addr), +NULL , &offset,NULL , namebuf); +if (!sym_name) +return ERR_PTR (-ENOENT ); + +if (strncmp (sym_name, p->symbol_name,KSYM_NAME_LEN ) + || offset != p->offset) { +pr_err ("Incorrect symbol or offset, should be " +"symbol=%s, offset=%ld.\n" , sym_name, offset); + goto invalid; + } + }else if (p->symbol_name) { +/* Only symbol case */ kprobe_lookup_name (p->symbol_name, addr);if (!addr)return ERR_PTR (-ENOENT ); + }else { +/* +* Only address case. +* Since we later will do sanity check of the +* address range in check_kprobe_address_safe(), +* do nothing here. +*/ } addr = (kprobe_opcode_t *)(((char *)addr) + p->offset);
Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Quoted 49 lines · Jianyu Zhan
Hi, I found that this patch wasn't merged into mainline during this merge window(maybe it wasn't cooked in any tree), while it has been acked-by for a couple of days.
Ingo, would you mind queueing this one? Thanks.
-----<8-----
Currently, if user specifies both symbol name and address, we just bail out.
This might be too rude. This patch makes it give more tolerance. If both are specified, check address first, if the symbol found does not match the one user specify, print a waring. If not found, return
-ENOENT, because some symbols might have muplitple instances, we don't bother to check symbol name.Acked-by Masami Hiramatsu <[email protected]>Signed-off-by Jianyu Zhan <[email protected]>--- Documentation/kprobes.txt | 4 +++- kernel/kprobes.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-)Documentation/kprobes.txt +3
-1@@ -358,7 +358,9 @@ to install a probepoint is known. This field is used to calculate the probepoint. 3. Specify either the kprobe "symbol_name" OR the "addr". If both are -specified, kprobe registration will fail with -EINVAL. +specified, only check "addr", because some symbols might have muplitple +instances. If neither is specified, kprobe registration will fail +with -EINVAL. 4. With CISC architectures (such as i386 and x86_64), the kprobes code does not validate if the kprobe.addr is at an instruction boundary.kernel/kprobes.c +2
-0@@ -1358,15 +1358,41 @@ static bool within_kprobe_blacklist(unsigned long addr)static kprobe_opcode_t *kprobe_addr (struct kprobe *p) {kprobe_opcode_t *addr = p->addr; +char namebuf[KSYM_NAME_LEN ]; +const char *sym_name =NULL ;
kernel/kprobes.c static bool within_kprobe_blacklist(unsigned long addr) · line 1369
Quoted 10 lines
kernel/kprobes.c +4
-3+unsigned long offset; -if ((p->symbol_name && p->addr) || - (!p->symbol_name && !p->addr)) +if (!p->symbol_name && !p->addr) goto invalid; -if (p->symbol_name) { +/* +* Some symbols might have muplitple instances,
s/multiple
kernel/kprobes.c static bool within_kprobe_blacklist(unsigned long addr) · line 1370
Quoted 1 line
kernel/kprobes.c +1
-0+* so if both specified, only check address.
s/:
* so if both are specified, only check the address.
kernel/kprobes.c static bool within_kprobe_blacklist(unsigned long addr) · line 1392
Quoted 4 lines
kernel/kprobes.c +4
-0+ }else { +/* +* Only address case. +* Since we later will do sanity check of the
'will do a sanity check' or 'will do sanity checking'
Thanks,
Ingo
Hi, Ingo,
Here is the new patch with typo fixed.
Thanks.
---8<---
Currently, if user specifies both symbol name and address, we just bail out.
This might be too rude. This patch makes it give more tolerance. If both are specified, check address first, if the symbol found does not match the one user specify, print a waring. If not found, return -ENOENT, because some symbols might have muplitple instances, we don't bother to check symbol name.
--- Documentation/kprobes.txt | 4 +++- kernel/kprobes.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-)
Documentation/kprobes.txt +3 -1
@@ -358,7 +358,9 @@ to install a probepoint is known. This field is used to calculate the probepoint. 3. Specify either the kprobe "symbol_name" OR the "addr". If both are -specified, kprobe registration will fail with -EINVAL. +specified, only check "addr", because some symbols might have multiple +instances. If neither is specified, kprobe registration will fail +with -EINVAL. 4. With CISC architectures (such as i386 and x86_64), the kprobes code does not validate if the kprobe.addr is at an instruction boundary.
kernel/kprobes.c +29 -3
@@ -1358,15 +1358,41 @@ static bool within_kprobe_blacklist(unsigned long addr)static kprobe_opcode_t *kprobe_addr (struct kprobe *p) {kprobe_opcode_t *addr = p->addr; +char namebuf[KSYM_NAME_LEN ]; +const char *sym_name =NULL ; +unsigned long offset; -if ((p->symbol_name && p->addr) || - (!p->symbol_name && !p->addr)) +if (!p->symbol_name && !p->addr) goto invalid; -if (p->symbol_name) { +/* +* Some symbols might have multiple instances, +* so if both are specified, only check address. +*/ +if (unlikely (p->addr && p->symbol_name)) { + sym_name =kallsyms_lookup ((unsigned long )(p->addr), +NULL , &offset,NULL , namebuf); +if (!sym_name) +return ERR_PTR (-ENOENT ); + +if (strncmp (sym_name, p->symbol_name,KSYM_NAME_LEN ) + || offset != p->offset) { +pr_err ("Incorrect symbol or offset, should be " +"symbol=%s, offset=%ld.\n" , sym_name, offset); + goto invalid; + } + }else if (p->symbol_name) { +/* Only symbol case */ kprobe_lookup_name (p->symbol_name, addr);if (!addr)return ERR_PTR (-ENOENT ); + }else { +/* +* Only address case. +* Since we later will do a sanity check of the +* address range in check_kprobe_address_safe(), +* do nothing here. +*/ } addr = (kprobe_opcode_t *)(((char *)addr) + p->offset);
Signature · 1 line
2.0.0
Jianyu Zhan
Acked-by Masami HiramatsuSorry for the noise,
plz add these Acked-by and Signed-off-by:
Thanks,
Jianyu Zhan
Quoted 88 lines · Jianyu Zhan
Hi, Ingo,
Here is the new patch with typo fixed.
Thanks.
---8<---
Currently, if user specifies both symbol name and address, we just bail out.
This might be too rude. This patch makes it give more tolerance. If both are specified, check address first, if the symbol found does not match the one user specify, print a waring. If not found, return
-ENOENT, because some symbols might have muplitple instances, we don't bother to check symbol name.--- Documentation/kprobes.txt | 4 +++- kernel/kprobes.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-)Documentation/kprobes.txt +3
-1@@ -358,7 +358,9 @@ to install a probepoint is known. This field is used to calculate the probepoint. 3. Specify either the kprobe "symbol_name" OR the "addr". If both are -specified, kprobe registration will fail with -EINVAL. +specified, only check "addr", because some symbols might have multiple +instances. If neither is specified, kprobe registration will fail +with -EINVAL. 4. With CISC architectures (such as i386 and x86_64), the kprobes code does not validate if the kprobe.addr is at an instruction boundary.kernel/kprobes.c +29
-4@@ -1358,15 +1358,41 @@ static bool within_kprobe_blacklist(unsigned long addr)static kprobe_opcode_t *kprobe_addr (struct kprobe *p) {kprobe_opcode_t *addr = p->addr; +char namebuf[KSYM_NAME_LEN ]; +const char *sym_name =NULL ; +unsigned long offset; -if ((p->symbol_name && p->addr) || - (!p->symbol_name && !p->addr)) +if (!p->symbol_name && !p->addr) goto invalid; -if (p->symbol_name) { +/* +* Some symbols might have multiple instances, +* so if both are specified, only check address. +*/ +if (unlikely (p->addr && p->symbol_name)) { + sym_name =kallsyms_lookup ((unsigned long )(p->addr), +NULL , &offset,NULL , namebuf); +if (!sym_name) +return ERR_PTR (-ENOENT ); + +if (strncmp (sym_name, p->symbol_name,KSYM_NAME_LEN ) + || offset != p->offset) { +pr_err ("Incorrect symbol or offset, should be " +"symbol=%s, offset=%ld.\n" , sym_name, offset); + goto invalid; + } + }else if (p->symbol_name) { +/* Only symbol case */ kprobe_lookup_name (p->symbol_name, addr);if (!addr)return ERR_PTR (-ENOENT ); + }else { +/* +* Only address case. +* Since we later will do a sanity check of the +* address range in check_kprobe_address_safe(), +* do nothing here. +*/ } addr = (kprobe_opcode_t *)(((char *)addr) + p->offset); --2.0.0
Hi Jianyu,
Quoted 3 lines · Jianyu Zhan
Sorry for the noise,
plz add these Acked-by and Signed-off-by:
I think you'd better to send it as a formal patch.
Thanks,
Namhyung
Quoted 101 lines
Acked-by Masami Hiramatsu <[email protected]>Signed-off-by Jianyu Zhan <[email protected]>Thanks,
Jianyu ZhanQuoted 86 lines · Jianyu Zhan
Hi, Ingo,
Here is the new patch with typo fixed.
Thanks.
---8<---
Currently, if user specifies both symbol name and address, we just bail out.
This might be too rude. This patch makes it give more tolerance. If both are specified, check address first, if the symbol found does not match the one user specify, print a waring. If not found, return
-ENOENT, because some symbols might have muplitple instances, we don't bother to check symbol name.--- Documentation/kprobes.txt | 4 +++- kernel/kprobes.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-)Documentation/kprobes.txt +3
-1@@ -358,7 +358,9 @@ to install a probepoint is known. This field is used to calculate the probepoint. 3. Specify either the kprobe "symbol_name" OR the "addr". If both are -specified, kprobe registration will fail with -EINVAL. +specified, only check "addr", because some symbols might have multiple +instances. If neither is specified, kprobe registration will fail +with -EINVAL. 4. With CISC architectures (such as i386 and x86_64), the kprobes code does not validate if the kprobe.addr is at an instruction boundary.kernel/kprobes.c +29
-4@@ -1358,15 +1358,41 @@ static bool within_kprobe_blacklist(unsigned long addr)static kprobe_opcode_t *kprobe_addr (struct kprobe *p) {kprobe_opcode_t *addr = p->addr; +char namebuf[KSYM_NAME_LEN ]; +const char *sym_name =NULL ; +unsigned long offset; -if ((p->symbol_name && p->addr) || - (!p->symbol_name && !p->addr)) +if (!p->symbol_name && !p->addr) goto invalid; -if (p->symbol_name) { +/* +* Some symbols might have multiple instances, +* so if both are specified, only check address. +*/ +if (unlikely (p->addr && p->symbol_name)) { + sym_name =kallsyms_lookup ((unsigned long )(p->addr), +NULL , &offset,NULL , namebuf); +if (!sym_name) +return ERR_PTR (-ENOENT ); + +if (strncmp (sym_name, p->symbol_name,KSYM_NAME_LEN ) + || offset != p->offset) { +pr_err ("Incorrect symbol or offset, should be " +"symbol=%s, offset=%ld.\n" , sym_name, offset); + goto invalid; + } + }else if (p->symbol_name) { +/* Only symbol case */ kprobe_lookup_name (p->symbol_name, addr);if (!addr)return ERR_PTR (-ENOENT ); + }else { +/* +* Only address case. +* Since we later will do a sanity check of the +* address range in check_kprobe_address_safe(), +* do nothing here. +*/ } addr = (kprobe_opcode_t *)(((char *)addr) + p->offset); --Quoted 2 lines
2.0.0
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Namhyung Kim
Hi Jianyu,
Quoted 3 lines · Jianyu Zhan
Sorry for the noise,
plz add these Acked-by and Signed-off-by:
I think you'd better to send it as a formal patch.
Agreed. Jianyu, please format it again. If you have a comment on it, you can reply the patch mail.
Thank you,
Quoted 112 lines
Thanks,
NamhyungQuoted 93 lines
Acked-by Masami Hiramatsu <[email protected]>Signed-off-by Jianyu Zhan <[email protected]>Thanks,
Jianyu ZhanQuoted 84 lines · Jianyu Zhan
Hi, Ingo,
Here is the new patch with typo fixed.
Thanks.
---8<---
Currently, if user specifies both symbol name and address, we just bail out.
This might be too rude. This patch makes it give more tolerance. If both are specified, check address first, if the symbol found does not match the one user specify, print a waring. If not found, return
-ENOENT, because some symbols might have muplitple instances, we don't bother to check symbol name.--- Documentation/kprobes.txt | 4 +++- kernel/kprobes.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-)Documentation/kprobes.txt +3
-1@@ -358,7 +358,9 @@ to install a probepoint is known. This field is used to calculate the probepoint. 3. Specify either the kprobe "symbol_name" OR the "addr". If both are -specified, kprobe registration will fail with -EINVAL. +specified, only check "addr", because some symbols might have multiple +instances. If neither is specified, kprobe registration will fail +with -EINVAL. 4. With CISC architectures (such as i386 and x86_64), the kprobes code does not validate if the kprobe.addr is at an instruction boundary.kernel/kprobes.c +29
-3@@ -1358,15 +1358,41 @@ static bool within_kprobe_blacklist(unsigned long addr)static kprobe_opcode_t *kprobe_addr (struct kprobe *p) {kprobe_opcode_t *addr = p->addr; +char namebuf[KSYM_NAME_LEN ]; +const char *sym_name =NULL ; +unsigned long offset; -if ((p->symbol_name && p->addr) || - (!p->symbol_name && !p->addr)) +if (!p->symbol_name && !p->addr) goto invalid; -if (p->symbol_name) { +/* +* Some symbols might have multiple instances, +* so if both are specified, only check address. +*/ +if (unlikely (p->addr && p->symbol_name)) { + sym_name =kallsyms_lookup ((unsigned long )(p->addr), +NULL , &offset,NULL , namebuf); +if (!sym_name) +return ERR_PTR (-ENOENT ); + +if (strncmp (sym_name, p->symbol_name,KSYM_NAME_LEN ) + || offset != p->offset) { +pr_err ("Incorrect symbol or offset, should be " +"symbol=%s, offset=%ld.\n" , sym_name, offset); + goto invalid; + } + }else if (p->symbol_name) { +/* Only symbol case */ kprobe_lookup_name (p->symbol_name, addr);if (!addr)return ERR_PTR (-ENOENT ); + }else { +/* +* Only address case. +* Since we later will do a sanity check of the +* address range in check_kprobe_address_safe(), +* do nothing here. +*/ }Quoted 8 lines
Quoted 4 lines
kernel/kprobes.c +0
-1addr = (kprobe_opcode_t *)(((char *)addr) + p->offset); --2.0.0
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]