diff options
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r-- | lib/vsprintf.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index c150d3dafff..d3023df8477 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -936,6 +936,8 @@ char *uuid_string(char *buf, char *end, const u8 *addr, | |||
936 | return string(buf, end, uuid, spec); | 936 | return string(buf, end, uuid, spec); |
937 | } | 937 | } |
938 | 938 | ||
939 | int kptr_restrict = 1; | ||
940 | |||
939 | /* | 941 | /* |
940 | * Show a '%p' thing. A kernel extension is that the '%p' is followed | 942 | * Show a '%p' thing. A kernel extension is that the '%p' is followed |
941 | * by an extra set of alphanumeric characters that are extended format | 943 | * by an extra set of alphanumeric characters that are extended format |
@@ -979,6 +981,7 @@ char *uuid_string(char *buf, char *end, const u8 *addr, | |||
979 | * Implements a "recursive vsnprintf". | 981 | * Implements a "recursive vsnprintf". |
980 | * Do not use this feature without some mechanism to verify the | 982 | * Do not use this feature without some mechanism to verify the |
981 | * correctness of the format string and va_list arguments. | 983 | * correctness of the format string and va_list arguments. |
984 | * - 'K' For a kernel pointer that should be hidden from unprivileged users | ||
982 | * | 985 | * |
983 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 | 986 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 |
984 | * function pointers are really function descriptors, which contain a | 987 | * function pointers are really function descriptors, which contain a |
@@ -1035,6 +1038,25 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
1035 | return buf + vsnprintf(buf, end - buf, | 1038 | return buf + vsnprintf(buf, end - buf, |
1036 | ((struct va_format *)ptr)->fmt, | 1039 | ((struct va_format *)ptr)->fmt, |
1037 | *(((struct va_format *)ptr)->va)); | 1040 | *(((struct va_format *)ptr)->va)); |
1041 | case 'K': | ||
1042 | /* | ||
1043 | * %pK cannot be used in IRQ context because its test | ||
1044 | * for CAP_SYSLOG would be meaningless. | ||
1045 | */ | ||
1046 | if (in_irq() || in_serving_softirq() || in_nmi()) { | ||
1047 | if (spec.field_width == -1) | ||
1048 | spec.field_width = 2 * sizeof(void *); | ||
1049 | return string(buf, end, "pK-error", spec); | ||
1050 | } else if ((kptr_restrict == 0) || | ||
1051 | (kptr_restrict == 1 && | ||
1052 | has_capability_noaudit(current, CAP_SYSLOG))) | ||
1053 | break; | ||
1054 | |||
1055 | if (spec.field_width == -1) { | ||
1056 | spec.field_width = 2 * sizeof(void *); | ||
1057 | spec.flags |= ZEROPAD; | ||
1058 | } | ||
1059 | return number(buf, end, 0, spec); | ||
1038 | } | 1060 | } |
1039 | spec.flags |= SMALL; | 1061 | spec.flags |= SMALL; |
1040 | if (spec.field_width == -1) { | 1062 | if (spec.field_width == -1) { |
@@ -1451,7 +1473,7 @@ EXPORT_SYMBOL(vsnprintf); | |||
1451 | * @args: Arguments for the format string | 1473 | * @args: Arguments for the format string |
1452 | * | 1474 | * |
1453 | * The return value is the number of characters which have been written into | 1475 | * The return value is the number of characters which have been written into |
1454 | * the @buf not including the trailing '\0'. If @size is <= 0 the function | 1476 | * the @buf not including the trailing '\0'. If @size is == 0 the function |
1455 | * returns 0. | 1477 | * returns 0. |
1456 | * | 1478 | * |
1457 | * Call this function if you are already dealing with a va_list. | 1479 | * Call this function if you are already dealing with a va_list. |
@@ -1465,7 +1487,11 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1465 | 1487 | ||
1466 | i = vsnprintf(buf, size, fmt, args); | 1488 | i = vsnprintf(buf, size, fmt, args); |
1467 | 1489 | ||
1468 | return (i >= size) ? (size - 1) : i; | 1490 | if (likely(i < size)) |
1491 | return i; | ||
1492 | if (size != 0) | ||
1493 | return size - 1; | ||
1494 | return 0; | ||
1469 | } | 1495 | } |
1470 | EXPORT_SYMBOL(vscnprintf); | 1496 | EXPORT_SYMBOL(vscnprintf); |
1471 | 1497 | ||
@@ -1513,14 +1539,10 @@ int scnprintf(char *buf, size_t size, const char *fmt, ...) | |||
1513 | int i; | 1539 | int i; |
1514 | 1540 | ||
1515 | va_start(args, fmt); | 1541 | va_start(args, fmt); |
1516 | i = vsnprintf(buf, size, fmt, args); | 1542 | i = vscnprintf(buf, size, fmt, args); |
1517 | va_end(args); | 1543 | va_end(args); |
1518 | 1544 | ||
1519 | if (likely(i < size)) | 1545 | return i; |
1520 | return i; | ||
1521 | if (size != 0) | ||
1522 | return size - 1; | ||
1523 | return 0; | ||
1524 | } | 1546 | } |
1525 | EXPORT_SYMBOL(scnprintf); | 1547 | EXPORT_SYMBOL(scnprintf); |
1526 | 1548 | ||