diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-15 14:08:27 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-15 14:08:27 -0400 |
commit | d488d3a4ce08e96dad5cb3b6117517d57ccec98f (patch) | |
tree | 169b09c589e38f6d5f2ea0a9e25c6a9fb3ebf783 | |
parent | cb906953d2c3fd450655d9fa833f03690ad50c23 (diff) | |
parent | 5deeb5cece3f9b30c8129786726b9d02c412c8ca (diff) |
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security
Pull security subsystem updates from James Morris:
"Highlights for this window:
- improved AVC hashing for SELinux by John Brooks and Stephen Smalley
- addition of an unconfined label to Smack
- Smack documentation update
- TPM driver updates"
* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (28 commits)
lsm: copy comm before calling audit_log to avoid race in string printing
tomoyo: Do not generate empty policy files
tomoyo: Use if_changed when generating builtin-policy.h
tomoyo: Use bin2c to generate builtin-policy.h
selinux: increase avtab max buckets
selinux: Use a better hash function for avtab
selinux: convert avtab hash table to flex_array
selinux: reconcile security_netlbl_secattr_to_sid() and mls_import_netlbl_cat()
selinux: remove unnecessary pointer reassignment
Smack: Updates for Smack documentation
tpm/st33zp24/spi: Add missing device table for spi phy.
tpm/st33zp24: Add proper wait for ordinal duration in case of irq mode
smack: Fix gcc warning from unused smack_syslog_lock mutex in smackfs.c
Smack: Allow an unconfined label in bringup mode
Smack: getting the Smack security context of keys
Smack: Assign smack_known_web as default smk_in label for kernel thread's socket
tpm/tpm_infineon: Use struct dev_pm_ops for power management
MAINTAINERS: Add Jason as designated reviewer for TPM
tpm: Update KConfig text to include TPM2.0 FIFO chips
tpm/st33zp24/dts/st33zp24-spi: Add dts documentation for st33zp24 spi phy
...
31 files changed, 1953 insertions, 1156 deletions
diff --git a/Documentation/devicetree/bindings/security/tpm/st33zp24-spi.txt b/Documentation/devicetree/bindings/security/tpm/st33zp24-spi.txt new file mode 100644 index 000000000000..158b0165e01c --- /dev/null +++ b/Documentation/devicetree/bindings/security/tpm/st33zp24-spi.txt | |||
@@ -0,0 +1,34 @@ | |||
1 | * STMicroelectronics SAS. ST33ZP24 TPM SoC | ||
2 | |||
3 | Required properties: | ||
4 | - compatible: Should be "st,st33zp24-spi". | ||
5 | - spi-max-frequency: Maximum SPI frequency (<= 10000000). | ||
6 | |||
7 | Optional ST33ZP24 Properties: | ||
8 | - interrupt-parent: phandle for the interrupt gpio controller | ||
9 | - interrupts: GPIO interrupt to which the chip is connected | ||
10 | - lpcpd-gpios: Output GPIO pin used for ST33ZP24 power management D1/D2 state. | ||
11 | If set, power must be present when the platform is going into sleep/hibernate mode. | ||
12 | |||
13 | Optional SoC Specific Properties: | ||
14 | - pinctrl-names: Contains only one value - "default". | ||
15 | - pintctrl-0: Specifies the pin control groups used for this controller. | ||
16 | |||
17 | Example (for ARM-based BeagleBoard xM with ST33ZP24 on SPI4): | ||
18 | |||
19 | &mcspi4 { | ||
20 | |||
21 | status = "okay"; | ||
22 | |||
23 | st33zp24@0 { | ||
24 | |||
25 | compatible = "st,st33zp24-spi"; | ||
26 | |||
27 | spi-max-frequency = <10000000>; | ||
28 | |||
29 | interrupt-parent = <&gpio5>; | ||
30 | interrupts = <7 IRQ_TYPE_LEVEL_HIGH>; | ||
31 | |||
32 | lpcpd-gpios = <&gpio5 15 GPIO_ACTIVE_HIGH>; | ||
33 | }; | ||
34 | }; | ||
diff --git a/Documentation/security/Smack.txt b/Documentation/security/Smack.txt index b6ef7e9dba30..abc82f85215b 100644 --- a/Documentation/security/Smack.txt +++ b/Documentation/security/Smack.txt | |||
@@ -33,11 +33,18 @@ The current git repository for Smack user space is: | |||
33 | git://github.com/smack-team/smack.git | 33 | git://github.com/smack-team/smack.git |
34 | 34 | ||
35 | This should make and install on most modern distributions. | 35 | This should make and install on most modern distributions. |
36 | There are three commands included in smackutil: | 36 | There are five commands included in smackutil: |
37 | 37 | ||
38 | smackload - properly formats data for writing to /smack/load | ||
39 | smackcipso - properly formats data for writing to /smack/cipso | ||
40 | chsmack - display or set Smack extended attribute values | 38 | chsmack - display or set Smack extended attribute values |
39 | smackctl - load the Smack access rules | ||
40 | smackaccess - report if a process with one label has access | ||
41 | to an object with another | ||
42 | |||
43 | These two commands are obsolete with the introduction of | ||
44 | the smackfs/load2 and smackfs/cipso2 interfaces. | ||
45 | |||
46 | smackload - properly formats data for writing to smackfs/load | ||
47 | smackcipso - properly formats data for writing to smackfs/cipso | ||
41 | 48 | ||
42 | In keeping with the intent of Smack, configuration data is | 49 | In keeping with the intent of Smack, configuration data is |
43 | minimal and not strictly required. The most important | 50 | minimal and not strictly required. The most important |
@@ -47,9 +54,9 @@ of this, but it can be manually as well. | |||
47 | 54 | ||
48 | Add this line to /etc/fstab: | 55 | Add this line to /etc/fstab: |
49 | 56 | ||
50 | smackfs /smack smackfs smackfsdef=* 0 0 | 57 | smackfs /sys/fs/smackfs smackfs defaults 0 0 |
51 | 58 | ||
52 | and create the /smack directory for mounting. | 59 | The /sys/fs/smackfs directory is created by the kernel. |
53 | 60 | ||
54 | Smack uses extended attributes (xattrs) to store labels on filesystem | 61 | Smack uses extended attributes (xattrs) to store labels on filesystem |
55 | objects. The attributes are stored in the extended attribute security | 62 | objects. The attributes are stored in the extended attribute security |
@@ -92,13 +99,13 @@ There are multiple ways to set a Smack label on a file: | |||
92 | # attr -S -s SMACK64 -V "value" path | 99 | # attr -S -s SMACK64 -V "value" path |
93 | # chsmack -a value path | 100 | # chsmack -a value path |
94 | 101 | ||
95 | A process can see the smack label it is running with by | 102 | A process can see the Smack label it is running with by |
96 | reading /proc/self/attr/current. A process with CAP_MAC_ADMIN | 103 | reading /proc/self/attr/current. A process with CAP_MAC_ADMIN |
97 | can set the process smack by writing there. | 104 | can set the process Smack by writing there. |
98 | 105 | ||
99 | Most Smack configuration is accomplished by writing to files | 106 | Most Smack configuration is accomplished by writing to files |
100 | in the smackfs filesystem. This pseudo-filesystem is usually | 107 | in the smackfs filesystem. This pseudo-filesystem is mounted |
101 | mounted on /smack. | 108 | on /sys/fs/smackfs. |
102 | 109 | ||
103 | access | 110 | access |
104 | This interface reports whether a subject with the specified | 111 | This interface reports whether a subject with the specified |
@@ -206,23 +213,30 @@ onlycap | |||
206 | file or cleared by writing "-" to the file. | 213 | file or cleared by writing "-" to the file. |
207 | ptrace | 214 | ptrace |
208 | This is used to define the current ptrace policy | 215 | This is used to define the current ptrace policy |
209 | 0 - default: this is the policy that relies on smack access rules. | 216 | 0 - default: this is the policy that relies on Smack access rules. |
210 | For the PTRACE_READ a subject needs to have a read access on | 217 | For the PTRACE_READ a subject needs to have a read access on |
211 | object. For the PTRACE_ATTACH a read-write access is required. | 218 | object. For the PTRACE_ATTACH a read-write access is required. |
212 | 1 - exact: this is the policy that limits PTRACE_ATTACH. Attach is | 219 | 1 - exact: this is the policy that limits PTRACE_ATTACH. Attach is |
213 | only allowed when subject's and object's labels are equal. | 220 | only allowed when subject's and object's labels are equal. |
214 | PTRACE_READ is not affected. Can be overriden with CAP_SYS_PTRACE. | 221 | PTRACE_READ is not affected. Can be overridden with CAP_SYS_PTRACE. |
215 | 2 - draconian: this policy behaves like the 'exact' above with an | 222 | 2 - draconian: this policy behaves like the 'exact' above with an |
216 | exception that it can't be overriden with CAP_SYS_PTRACE. | 223 | exception that it can't be overridden with CAP_SYS_PTRACE. |
217 | revoke-subject | 224 | revoke-subject |
218 | Writing a Smack label here sets the access to '-' for all access | 225 | Writing a Smack label here sets the access to '-' for all access |
219 | rules with that subject label. | 226 | rules with that subject label. |
227 | unconfined | ||
228 | If the kernel is configured with CONFIG_SECURITY_SMACK_BRINGUP | ||
229 | a process with CAP_MAC_ADMIN can write a label into this interface. | ||
230 | Thereafter, accesses that involve that label will be logged and | ||
231 | the access permitted if it wouldn't be otherwise. Note that this | ||
232 | is dangerous and can ruin the proper labeling of your system. | ||
233 | It should never be used in production. | ||
220 | 234 | ||
221 | You can add access rules in /etc/smack/accesses. They take the form: | 235 | You can add access rules in /etc/smack/accesses. They take the form: |
222 | 236 | ||
223 | subjectlabel objectlabel access | 237 | subjectlabel objectlabel access |
224 | 238 | ||
225 | access is a combination of the letters rwxa which specify the | 239 | access is a combination of the letters rwxatb which specify the |
226 | kind of access permitted a subject with subjectlabel on an | 240 | kind of access permitted a subject with subjectlabel on an |
227 | object with objectlabel. If there is no rule no access is allowed. | 241 | object with objectlabel. If there is no rule no access is allowed. |
228 | 242 | ||
@@ -318,8 +332,9 @@ each of the subject and the object. | |||
318 | 332 | ||
319 | Labels | 333 | Labels |
320 | 334 | ||
321 | Smack labels are ASCII character strings, one to twenty-three characters in | 335 | Smack labels are ASCII character strings. They can be up to 255 characters |
322 | length. Single character labels using special characters, that being anything | 336 | long, but keeping them to twenty-three characters is recommended. |
337 | Single character labels using special characters, that being anything | ||
323 | other than a letter or digit, are reserved for use by the Smack development | 338 | other than a letter or digit, are reserved for use by the Smack development |
324 | team. Smack labels are unstructured, case sensitive, and the only operation | 339 | team. Smack labels are unstructured, case sensitive, and the only operation |
325 | ever performed on them is comparison for equality. Smack labels cannot | 340 | ever performed on them is comparison for equality. Smack labels cannot |
@@ -335,10 +350,9 @@ There are some predefined labels: | |||
335 | ? Pronounced "huh", a single question mark character. | 350 | ? Pronounced "huh", a single question mark character. |
336 | @ Pronounced "web", a single at sign character. | 351 | @ Pronounced "web", a single at sign character. |
337 | 352 | ||
338 | Every task on a Smack system is assigned a label. System tasks, such as | 353 | Every task on a Smack system is assigned a label. The Smack label |
339 | init(8) and systems daemons, are run with the floor ("_") label. User tasks | 354 | of a process will usually be assigned by the system initialization |
340 | are assigned labels according to the specification found in the | 355 | mechanism. |
341 | /etc/smack/user configuration file. | ||
342 | 356 | ||
343 | Access Rules | 357 | Access Rules |
344 | 358 | ||
@@ -393,6 +407,7 @@ describe access modes: | |||
393 | w: indicates that write access should be granted. | 407 | w: indicates that write access should be granted. |
394 | x: indicates that execute access should be granted. | 408 | x: indicates that execute access should be granted. |
395 | t: indicates that the rule requests transmutation. | 409 | t: indicates that the rule requests transmutation. |
410 | b: indicates that the rule should be reported for bring-up. | ||
396 | 411 | ||
397 | Uppercase values for the specification letters are allowed as well. | 412 | Uppercase values for the specification letters are allowed as well. |
398 | Access mode specifications can be in any order. Examples of acceptable rules | 413 | Access mode specifications can be in any order. Examples of acceptable rules |
@@ -402,6 +417,7 @@ are: | |||
402 | Secret Unclass R | 417 | Secret Unclass R |
403 | Manager Game x | 418 | Manager Game x |
404 | User HR w | 419 | User HR w |
420 | Snap Crackle rwxatb | ||
405 | New Old rRrRr | 421 | New Old rRrRr |
406 | Closed Off - | 422 | Closed Off - |
407 | 423 | ||
@@ -413,7 +429,7 @@ Examples of unacceptable rules are: | |||
413 | 429 | ||
414 | Spaces are not allowed in labels. Since a subject always has access to files | 430 | Spaces are not allowed in labels. Since a subject always has access to files |
415 | with the same label specifying a rule for that case is pointless. Only | 431 | with the same label specifying a rule for that case is pointless. Only |
416 | valid letters (rwxatRWXAT) and the dash ('-') character are allowed in | 432 | valid letters (rwxatbRWXATB) and the dash ('-') character are allowed in |
417 | access specifications. The dash is a placeholder, so "a-r" is the same | 433 | access specifications. The dash is a placeholder, so "a-r" is the same |
418 | as "ar". A lone dash is used to specify that no access should be allowed. | 434 | as "ar". A lone dash is used to specify that no access should be allowed. |
419 | 435 | ||
@@ -462,16 +478,11 @@ receiver. The receiver is not required to have read access to the sender. | |||
462 | Setting Access Rules | 478 | Setting Access Rules |
463 | 479 | ||
464 | The configuration file /etc/smack/accesses contains the rules to be set at | 480 | The configuration file /etc/smack/accesses contains the rules to be set at |
465 | system startup. The contents are written to the special file /smack/load. | 481 | system startup. The contents are written to the special file |
466 | Rules can be written to /smack/load at any time and take effect immediately. | 482 | /sys/fs/smackfs/load2. Rules can be added at any time and take effect |
467 | For any pair of subject and object labels there can be only one rule, with the | 483 | immediately. For any pair of subject and object labels there can be only |
468 | most recently specified overriding any earlier specification. | 484 | one rule, with the most recently specified overriding any earlier |
469 | 485 | specification. | |
470 | The program smackload is provided to ensure data is formatted | ||
471 | properly when written to /smack/load. This program reads lines | ||
472 | of the form | ||
473 | |||
474 | subjectlabel objectlabel mode. | ||
475 | 486 | ||
476 | Task Attribute | 487 | Task Attribute |
477 | 488 | ||
@@ -488,7 +499,10 @@ only be changed by a process with privilege. | |||
488 | 499 | ||
489 | Privilege | 500 | Privilege |
490 | 501 | ||
491 | A process with CAP_MAC_OVERRIDE is privileged. | 502 | A process with CAP_MAC_OVERRIDE or CAP_MAC_ADMIN is privileged. |
503 | CAP_MAC_OVERRIDE allows the process access to objects it would | ||
504 | be denied otherwise. CAP_MAC_ADMIN allows a process to change | ||
505 | Smack data, including rules and attributes. | ||
492 | 506 | ||
493 | Smack Networking | 507 | Smack Networking |
494 | 508 | ||
@@ -510,14 +524,14 @@ intervention. Unlabeled packets that come into the system will be given the | |||
510 | ambient label. | 524 | ambient label. |
511 | 525 | ||
512 | Smack requires configuration in the case where packets from a system that is | 526 | Smack requires configuration in the case where packets from a system that is |
513 | not smack that speaks CIPSO may be encountered. Usually this will be a Trusted | 527 | not Smack that speaks CIPSO may be encountered. Usually this will be a Trusted |
514 | Solaris system, but there are other, less widely deployed systems out there. | 528 | Solaris system, but there are other, less widely deployed systems out there. |
515 | CIPSO provides 3 important values, a Domain Of Interpretation (DOI), a level, | 529 | CIPSO provides 3 important values, a Domain Of Interpretation (DOI), a level, |
516 | and a category set with each packet. The DOI is intended to identify a group | 530 | and a category set with each packet. The DOI is intended to identify a group |
517 | of systems that use compatible labeling schemes, and the DOI specified on the | 531 | of systems that use compatible labeling schemes, and the DOI specified on the |
518 | smack system must match that of the remote system or packets will be | 532 | Smack system must match that of the remote system or packets will be |
519 | discarded. The DOI is 3 by default. The value can be read from /smack/doi and | 533 | discarded. The DOI is 3 by default. The value can be read from |
520 | can be changed by writing to /smack/doi. | 534 | /sys/fs/smackfs/doi and can be changed by writing to /sys/fs/smackfs/doi. |
521 | 535 | ||
522 | The label and category set are mapped to a Smack label as defined in | 536 | The label and category set are mapped to a Smack label as defined in |
523 | /etc/smack/cipso. | 537 | /etc/smack/cipso. |
@@ -539,15 +553,13 @@ The ":" and "," characters are permitted in a Smack label but have no special | |||
539 | meaning. | 553 | meaning. |
540 | 554 | ||
541 | The mapping of Smack labels to CIPSO values is defined by writing to | 555 | The mapping of Smack labels to CIPSO values is defined by writing to |
542 | /smack/cipso. Again, the format of data written to this special file | 556 | /sys/fs/smackfs/cipso2. |
543 | is highly restrictive, so the program smackcipso is provided to | ||
544 | ensure the writes are done properly. This program takes mappings | ||
545 | on the standard input and sends them to /smack/cipso properly. | ||
546 | 557 | ||
547 | In addition to explicit mappings Smack supports direct CIPSO mappings. One | 558 | In addition to explicit mappings Smack supports direct CIPSO mappings. One |
548 | CIPSO level is used to indicate that the category set passed in the packet is | 559 | CIPSO level is used to indicate that the category set passed in the packet is |
549 | in fact an encoding of the Smack label. The level used is 250 by default. The | 560 | in fact an encoding of the Smack label. The level used is 250 by default. The |
550 | value can be read from /smack/direct and changed by writing to /smack/direct. | 561 | value can be read from /sys/fs/smackfs/direct and changed by writing to |
562 | /sys/fs/smackfs/direct. | ||
551 | 563 | ||
552 | Socket Attributes | 564 | Socket Attributes |
553 | 565 | ||
@@ -565,8 +577,8 @@ sockets. | |||
565 | Smack Netlabel Exceptions | 577 | Smack Netlabel Exceptions |
566 | 578 | ||
567 | You will often find that your labeled application has to talk to the outside, | 579 | You will often find that your labeled application has to talk to the outside, |
568 | unlabeled world. To do this there's a special file /smack/netlabel where you can | 580 | unlabeled world. To do this there's a special file /sys/fs/smackfs/netlabel |
569 | add some exceptions in the form of : | 581 | where you can add some exceptions in the form of : |
570 | @IP1 LABEL1 or | 582 | @IP1 LABEL1 or |
571 | @IP2/MASK LABEL2 | 583 | @IP2/MASK LABEL2 |
572 | 584 | ||
@@ -574,22 +586,22 @@ It means that your application will have unlabeled access to @IP1 if it has | |||
574 | write access on LABEL1, and access to the subnet @IP2/MASK if it has write | 586 | write access on LABEL1, and access to the subnet @IP2/MASK if it has write |
575 | access on LABEL2. | 587 | access on LABEL2. |
576 | 588 | ||
577 | Entries in the /smack/netlabel file are matched by longest mask first, like in | 589 | Entries in the /sys/fs/smackfs/netlabel file are matched by longest mask |
578 | classless IPv4 routing. | 590 | first, like in classless IPv4 routing. |
579 | 591 | ||
580 | A special label '@' and an option '-CIPSO' can be used there : | 592 | A special label '@' and an option '-CIPSO' can be used there : |
581 | @ means Internet, any application with any label has access to it | 593 | @ means Internet, any application with any label has access to it |
582 | -CIPSO means standard CIPSO networking | 594 | -CIPSO means standard CIPSO networking |
583 | 595 | ||
584 | If you don't know what CIPSO is and don't plan to use it, you can just do : | 596 | If you don't know what CIPSO is and don't plan to use it, you can just do : |
585 | echo 127.0.0.1 -CIPSO > /smack/netlabel | 597 | echo 127.0.0.1 -CIPSO > /sys/fs/smackfs/netlabel |
586 | echo 0.0.0.0/0 @ > /smack/netlabel | 598 | echo 0.0.0.0/0 @ > /sys/fs/smackfs/netlabel |
587 | 599 | ||
588 | If you use CIPSO on your 192.168.0.0/16 local network and need also unlabeled | 600 | If you use CIPSO on your 192.168.0.0/16 local network and need also unlabeled |
589 | Internet access, you can have : | 601 | Internet access, you can have : |
590 | echo 127.0.0.1 -CIPSO > /smack/netlabel | 602 | echo 127.0.0.1 -CIPSO > /sys/fs/smackfs/netlabel |
591 | echo 192.168.0.0/16 -CIPSO > /smack/netlabel | 603 | echo 192.168.0.0/16 -CIPSO > /sys/fs/smackfs/netlabel |
592 | echo 0.0.0.0/0 @ > /smack/netlabel | 604 | echo 0.0.0.0/0 @ > /sys/fs/smackfs/netlabel |
593 | 605 | ||
594 | 606 | ||
595 | Writing Applications for Smack | 607 | Writing Applications for Smack |
@@ -676,7 +688,7 @@ Smack auditing | |||
676 | If you want Smack auditing of security events, you need to set CONFIG_AUDIT | 688 | If you want Smack auditing of security events, you need to set CONFIG_AUDIT |
677 | in your kernel configuration. | 689 | in your kernel configuration. |
678 | By default, all denied events will be audited. You can change this behavior by | 690 | By default, all denied events will be audited. You can change this behavior by |
679 | writing a single character to the /smack/logging file : | 691 | writing a single character to the /sys/fs/smackfs/logging file : |
680 | 0 : no logging | 692 | 0 : no logging |
681 | 1 : log denied (default) | 693 | 1 : log denied (default) |
682 | 2 : log accepted | 694 | 2 : log accepted |
@@ -686,3 +698,20 @@ Events are logged as 'key=value' pairs, for each event you at least will get | |||
686 | the subject, the object, the rights requested, the action, the kernel function | 698 | the subject, the object, the rights requested, the action, the kernel function |
687 | that triggered the event, plus other pairs depending on the type of event | 699 | that triggered the event, plus other pairs depending on the type of event |
688 | audited. | 700 | audited. |
701 | |||
702 | Bringup Mode | ||
703 | |||
704 | Bringup mode provides logging features that can make application | ||
705 | configuration and system bringup easier. Configure the kernel with | ||
706 | CONFIG_SECURITY_SMACK_BRINGUP to enable these features. When bringup | ||
707 | mode is enabled accesses that succeed due to rules marked with the "b" | ||
708 | access mode will logged. When a new label is introduced for processes | ||
709 | rules can be added aggressively, marked with the "b". The logging allows | ||
710 | tracking of which rules actual get used for that label. | ||
711 | |||
712 | Another feature of bringup mode is the "unconfined" option. Writing | ||
713 | a label to /sys/fs/smackfs/unconfined makes subjects with that label | ||
714 | able to access any object, and objects with that label accessible to | ||
715 | all subjects. Any access that is granted because a label is unconfined | ||
716 | is logged. This feature is dangerous, as files and directories may | ||
717 | be created in places they couldn't if the policy were being enforced. | ||
diff --git a/MAINTAINERS b/MAINTAINERS index 7a8f367b4ebc..c72a7baec55c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -9968,6 +9968,7 @@ F: drivers/media/pci/tw68/ | |||
9968 | TPM DEVICE DRIVER | 9968 | TPM DEVICE DRIVER |
9969 | M: Peter Huewe <peterhuewe@gmx.de> | 9969 | M: Peter Huewe <peterhuewe@gmx.de> |
9970 | M: Marcel Selhorst <tpmdd@selhorst.net> | 9970 | M: Marcel Selhorst <tpmdd@selhorst.net> |
9971 | R: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> | ||
9971 | W: http://tpmdd.sourceforge.net | 9972 | W: http://tpmdd.sourceforge.net |
9972 | L: tpmdd-devel@lists.sourceforge.net (moderated for non-subscribers) | 9973 | L: tpmdd-devel@lists.sourceforge.net (moderated for non-subscribers) |
9973 | Q: git git://github.com/PeterHuewe/linux-tpmdd.git | 9974 | Q: git git://github.com/PeterHuewe/linux-tpmdd.git |
diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig index 9d4e37549eb2..3b84a8b1bfbe 100644 --- a/drivers/char/tpm/Kconfig +++ b/drivers/char/tpm/Kconfig | |||
@@ -25,13 +25,14 @@ menuconfig TCG_TPM | |||
25 | if TCG_TPM | 25 | if TCG_TPM |
26 | 26 | ||
27 | config TCG_TIS | 27 | config TCG_TIS |
28 | tristate "TPM Interface Specification 1.2 Interface" | 28 | tristate "TPM Interface Specification 1.2 Interface / TPM 2.0 FIFO Interface" |
29 | depends on X86 | 29 | depends on X86 |
30 | ---help--- | 30 | ---help--- |
31 | If you have a TPM security chip that is compliant with the | 31 | If you have a TPM security chip that is compliant with the |
32 | TCG TIS 1.2 TPM specification say Yes and it will be accessible | 32 | TCG TIS 1.2 TPM specification (TPM1.2) or the TCG PTP FIFO |
33 | from within Linux. To compile this driver as a module, choose | 33 | specification (TPM2.0) say Yes and it will be accessible from |
34 | M here; the module will be called tpm_tis. | 34 | within Linux. To compile this driver as a module, choose M here; |
35 | the module will be called tpm_tis. | ||
35 | 36 | ||
36 | config TCG_TIS_I2C_ATMEL | 37 | config TCG_TIS_I2C_ATMEL |
37 | tristate "TPM Interface Specification 1.2 Interface (I2C - Atmel)" | 38 | tristate "TPM Interface Specification 1.2 Interface (I2C - Atmel)" |
@@ -100,16 +101,6 @@ config TCG_IBMVTPM | |||
100 | will be accessible from within Linux. To compile this driver | 101 | will be accessible from within Linux. To compile this driver |
101 | as a module, choose M here; the module will be called tpm_ibmvtpm. | 102 | as a module, choose M here; the module will be called tpm_ibmvtpm. |
102 | 103 | ||
103 | config TCG_TIS_I2C_ST33 | ||
104 | tristate "TPM Interface Specification 1.2 Interface (I2C - STMicroelectronics)" | ||
105 | depends on I2C | ||
106 | depends on GPIOLIB | ||
107 | ---help--- | ||
108 | If you have a TPM security chip from STMicroelectronics working with | ||
109 | an I2C bus say Yes and it will be accessible from within Linux. | ||
110 | To compile this driver as a module, choose M here; the module will be | ||
111 | called tpm_i2c_stm_st33. | ||
112 | |||
113 | config TCG_XEN | 104 | config TCG_XEN |
114 | tristate "XEN TPM Interface" | 105 | tristate "XEN TPM Interface" |
115 | depends on TCG_TPM && XEN | 106 | depends on TCG_TPM && XEN |
@@ -131,4 +122,5 @@ config TCG_CRB | |||
131 | from within Linux. To compile this driver as a module, choose | 122 | from within Linux. To compile this driver as a module, choose |
132 | M here; the module will be called tpm_crb. | 123 | M here; the module will be called tpm_crb. |
133 | 124 | ||
125 | source "drivers/char/tpm/st33zp24/Kconfig" | ||
134 | endif # TCG_TPM | 126 | endif # TCG_TPM |
diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile index 990cf183931d..56e8f1f3dc7e 100644 --- a/drivers/char/tpm/Makefile +++ b/drivers/char/tpm/Makefile | |||
@@ -20,6 +20,6 @@ obj-$(CONFIG_TCG_NSC) += tpm_nsc.o | |||
20 | obj-$(CONFIG_TCG_ATMEL) += tpm_atmel.o | 20 | obj-$(CONFIG_TCG_ATMEL) += tpm_atmel.o |
21 | obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o | 21 | obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o |
22 | obj-$(CONFIG_TCG_IBMVTPM) += tpm_ibmvtpm.o | 22 | obj-$(CONFIG_TCG_IBMVTPM) += tpm_ibmvtpm.o |
23 | obj-$(CONFIG_TCG_TIS_I2C_ST33) += tpm_i2c_stm_st33.o | 23 | obj-$(CONFIG_TCG_TIS_ST33ZP24) += st33zp24/ |
24 | obj-$(CONFIG_TCG_XEN) += xen-tpmfront.o | 24 | obj-$(CONFIG_TCG_XEN) += xen-tpmfront.o |
25 | obj-$(CONFIG_TCG_CRB) += tpm_crb.o | 25 | obj-$(CONFIG_TCG_CRB) += tpm_crb.o |
diff --git a/drivers/char/tpm/st33zp24/Kconfig b/drivers/char/tpm/st33zp24/Kconfig new file mode 100644 index 000000000000..09cb727864f0 --- /dev/null +++ b/drivers/char/tpm/st33zp24/Kconfig | |||
@@ -0,0 +1,30 @@ | |||
1 | config TCG_TIS_ST33ZP24 | ||
2 | tristate "STMicroelectronics TPM Interface Specification 1.2 Interface" | ||
3 | depends on GPIOLIB | ||
4 | ---help--- | ||
5 | STMicroelectronics ST33ZP24 core driver. It implements the core | ||
6 | TPM1.2 logic and hooks into the TPM kernel APIs. Physical layers will | ||
7 | register against it. | ||
8 | |||
9 | To compile this driver as a module, choose m here. The module will be called | ||
10 | tpm_st33zp24. | ||
11 | |||
12 | config TCG_TIS_ST33ZP24_I2C | ||
13 | tristate "TPM 1.2 ST33ZP24 I2C support" | ||
14 | depends on TCG_TIS_ST33ZP24 | ||
15 | depends on I2C | ||
16 | ---help--- | ||
17 | This module adds support for the STMicroelectronics TPM security chip | ||
18 | ST33ZP24 with i2c interface. | ||
19 | To compile this driver as a module, choose M here; the module will be | ||
20 | called tpm_st33zp24_i2c. | ||
21 | |||
22 | config TCG_TIS_ST33ZP24_SPI | ||
23 | tristate "TPM 1.2 ST33ZP24 SPI support" | ||
24 | depends on TCG_TIS_ST33ZP24 | ||
25 | depends on SPI | ||
26 | ---help--- | ||
27 | This module adds support for the STMicroelectronics TPM security chip | ||
28 | ST33ZP24 with spi interface. | ||
29 | To compile this driver as a module, choose M here; the module will be | ||
30 | called tpm_st33zp24_spi. | ||
diff --git a/drivers/char/tpm/st33zp24/Makefile b/drivers/char/tpm/st33zp24/Makefile new file mode 100644 index 000000000000..74a722e5e068 --- /dev/null +++ b/drivers/char/tpm/st33zp24/Makefile | |||
@@ -0,0 +1,12 @@ | |||
1 | # | ||
2 | # Makefile for ST33ZP24 TPM 1.2 driver | ||
3 | # | ||
4 | |||
5 | tpm_st33zp24-objs = st33zp24.o | ||
6 | obj-$(CONFIG_TCG_TIS_ST33ZP24) += tpm_st33zp24.o | ||
7 | |||
8 | tpm_st33zp24_i2c-objs = i2c.o | ||
9 | obj-$(CONFIG_TCG_TIS_ST33ZP24_I2C) += tpm_st33zp24_i2c.o | ||
10 | |||
11 | tpm_st33zp24_spi-objs = spi.o | ||
12 | obj-$(CONFIG_TCG_TIS_ST33ZP24_SPI) += tpm_st33zp24_spi.o | ||
diff --git a/drivers/char/tpm/st33zp24/i2c.c b/drivers/char/tpm/st33zp24/i2c.c new file mode 100644 index 000000000000..ad1ee180e0c2 --- /dev/null +++ b/drivers/char/tpm/st33zp24/i2c.c | |||
@@ -0,0 +1,276 @@ | |||
1 | /* | ||
2 | * STMicroelectronics TPM I2C Linux driver for TPM ST33ZP24 | ||
3 | * Copyright (C) 2009 - 2015 STMicroelectronics | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/i2c.h> | ||
21 | #include <linux/gpio.h> | ||
22 | #include <linux/of_irq.h> | ||
23 | #include <linux/of_gpio.h> | ||
24 | #include <linux/tpm.h> | ||
25 | #include <linux/platform_data/st33zp24.h> | ||
26 | |||
27 | #include "st33zp24.h" | ||
28 | |||
29 | #define TPM_DUMMY_BYTE 0xAA | ||
30 | |||
31 | struct st33zp24_i2c_phy { | ||
32 | struct i2c_client *client; | ||
33 | u8 buf[TPM_BUFSIZE + 1]; | ||
34 | int io_lpcpd; | ||
35 | }; | ||
36 | |||
37 | /* | ||
38 | * write8_reg | ||
39 | * Send byte to the TIS register according to the ST33ZP24 I2C protocol. | ||
40 | * @param: tpm_register, the tpm tis register where the data should be written | ||
41 | * @param: tpm_data, the tpm_data to write inside the tpm_register | ||
42 | * @param: tpm_size, The length of the data | ||
43 | * @return: Returns negative errno, or else the number of bytes written. | ||
44 | */ | ||
45 | static int write8_reg(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size) | ||
46 | { | ||
47 | struct st33zp24_i2c_phy *phy = phy_id; | ||
48 | |||
49 | phy->buf[0] = tpm_register; | ||
50 | memcpy(phy->buf + 1, tpm_data, tpm_size); | ||
51 | return i2c_master_send(phy->client, phy->buf, tpm_size + 1); | ||
52 | } /* write8_reg() */ | ||
53 | |||
54 | /* | ||
55 | * read8_reg | ||
56 | * Recv byte from the TIS register according to the ST33ZP24 I2C protocol. | ||
57 | * @param: tpm_register, the tpm tis register where the data should be read | ||
58 | * @param: tpm_data, the TPM response | ||
59 | * @param: tpm_size, tpm TPM response size to read. | ||
60 | * @return: number of byte read successfully: should be one if success. | ||
61 | */ | ||
62 | static int read8_reg(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size) | ||
63 | { | ||
64 | struct st33zp24_i2c_phy *phy = phy_id; | ||
65 | u8 status = 0; | ||
66 | u8 data; | ||
67 | |||
68 | data = TPM_DUMMY_BYTE; | ||
69 | status = write8_reg(phy, tpm_register, &data, 1); | ||
70 | if (status == 2) | ||
71 | status = i2c_master_recv(phy->client, tpm_data, tpm_size); | ||
72 | return status; | ||
73 | } /* read8_reg() */ | ||
74 | |||
75 | /* | ||
76 | * st33zp24_i2c_send | ||
77 | * Send byte to the TIS register according to the ST33ZP24 I2C protocol. | ||
78 | * @param: phy_id, the phy description | ||
79 | * @param: tpm_register, the tpm tis register where the data should be written | ||
80 | * @param: tpm_data, the tpm_data to write inside the tpm_register | ||
81 | * @param: tpm_size, the length of the data | ||
82 | * @return: number of byte written successfully: should be one if success. | ||
83 | */ | ||
84 | static int st33zp24_i2c_send(void *phy_id, u8 tpm_register, u8 *tpm_data, | ||
85 | int tpm_size) | ||
86 | { | ||
87 | return write8_reg(phy_id, tpm_register | TPM_WRITE_DIRECTION, tpm_data, | ||
88 | tpm_size); | ||
89 | } | ||
90 | |||
91 | /* | ||
92 | * st33zp24_i2c_recv | ||
93 | * Recv byte from the TIS register according to the ST33ZP24 I2C protocol. | ||
94 | * @param: phy_id, the phy description | ||
95 | * @param: tpm_register, the tpm tis register where the data should be read | ||
96 | * @param: tpm_data, the TPM response | ||
97 | * @param: tpm_size, tpm TPM response size to read. | ||
98 | * @return: number of byte read successfully: should be one if success. | ||
99 | */ | ||
100 | static int st33zp24_i2c_recv(void *phy_id, u8 tpm_register, u8 *tpm_data, | ||
101 | int tpm_size) | ||
102 | { | ||
103 | return read8_reg(phy_id, tpm_register, tpm_data, tpm_size); | ||
104 | } | ||
105 | |||
106 | static const struct st33zp24_phy_ops i2c_phy_ops = { | ||
107 | .send = st33zp24_i2c_send, | ||
108 | .recv = st33zp24_i2c_recv, | ||
109 | }; | ||
110 | |||
111 | #ifdef CONFIG_OF | ||
112 | static int st33zp24_i2c_of_request_resources(struct st33zp24_i2c_phy *phy) | ||
113 | { | ||
114 | struct device_node *pp; | ||
115 | struct i2c_client *client = phy->client; | ||
116 | int gpio; | ||
117 | int ret; | ||
118 | |||
119 | pp = client->dev.of_node; | ||
120 | if (!pp) { | ||
121 | dev_err(&client->dev, "No platform data\n"); | ||
122 | return -ENODEV; | ||
123 | } | ||
124 | |||
125 | /* Get GPIO from device tree */ | ||
126 | gpio = of_get_named_gpio(pp, "lpcpd-gpios", 0); | ||
127 | if (gpio < 0) { | ||
128 | dev_err(&client->dev, | ||
129 | "Failed to retrieve lpcpd-gpios from dts.\n"); | ||
130 | phy->io_lpcpd = -1; | ||
131 | /* | ||
132 | * lpcpd pin is not specified. This is not an issue as | ||
133 | * power management can be also managed by TPM specific | ||
134 | * commands. So leave with a success status code. | ||
135 | */ | ||
136 | return 0; | ||
137 | } | ||
138 | /* GPIO request and configuration */ | ||
139 | ret = devm_gpio_request_one(&client->dev, gpio, | ||
140 | GPIOF_OUT_INIT_HIGH, "TPM IO LPCPD"); | ||
141 | if (ret) { | ||
142 | dev_err(&client->dev, "Failed to request lpcpd pin\n"); | ||
143 | return -ENODEV; | ||
144 | } | ||
145 | phy->io_lpcpd = gpio; | ||
146 | |||
147 | return 0; | ||
148 | } | ||
149 | #else | ||
150 | static int st33zp24_i2c_of_request_resources(struct st33zp24_i2c_phy *phy) | ||
151 | { | ||
152 | return -ENODEV; | ||
153 | } | ||
154 | #endif | ||
155 | |||
156 | static int st33zp24_i2c_request_resources(struct i2c_client *client, | ||
157 | struct st33zp24_i2c_phy *phy) | ||
158 | { | ||
159 | struct st33zp24_platform_data *pdata; | ||
160 | int ret; | ||
161 | |||
162 | pdata = client->dev.platform_data; | ||
163 | if (!pdata) { | ||
164 | dev_err(&client->dev, "No platform data\n"); | ||
165 | return -ENODEV; | ||
166 | } | ||
167 | |||
168 | /* store for late use */ | ||
169 | phy->io_lpcpd = pdata->io_lpcpd; | ||
170 | |||
171 | if (gpio_is_valid(pdata->io_lpcpd)) { | ||
172 | ret = devm_gpio_request_one(&client->dev, | ||
173 | pdata->io_lpcpd, GPIOF_OUT_INIT_HIGH, | ||
174 | "TPM IO_LPCPD"); | ||
175 | if (ret) { | ||
176 | dev_err(&client->dev, "Failed to request lpcpd pin\n"); | ||
177 | return ret; | ||
178 | } | ||
179 | } | ||
180 | |||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | /* | ||
185 | * st33zp24_i2c_probe initialize the TPM device | ||
186 | * @param: client, the i2c_client drescription (TPM I2C description). | ||
187 | * @param: id, the i2c_device_id struct. | ||
188 | * @return: 0 in case of success. | ||
189 | * -1 in other case. | ||
190 | */ | ||
191 | static int st33zp24_i2c_probe(struct i2c_client *client, | ||
192 | const struct i2c_device_id *id) | ||
193 | { | ||
194 | int ret; | ||
195 | struct st33zp24_platform_data *pdata; | ||
196 | struct st33zp24_i2c_phy *phy; | ||
197 | |||
198 | if (!client) { | ||
199 | pr_info("%s: i2c client is NULL. Device not accessible.\n", | ||
200 | __func__); | ||
201 | return -ENODEV; | ||
202 | } | ||
203 | |||
204 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { | ||
205 | dev_info(&client->dev, "client not i2c capable\n"); | ||
206 | return -ENODEV; | ||
207 | } | ||
208 | |||
209 | phy = devm_kzalloc(&client->dev, sizeof(struct st33zp24_i2c_phy), | ||
210 | GFP_KERNEL); | ||
211 | if (!phy) | ||
212 | return -ENOMEM; | ||
213 | |||
214 | phy->client = client; | ||
215 | pdata = client->dev.platform_data; | ||
216 | if (!pdata && client->dev.of_node) { | ||
217 | ret = st33zp24_i2c_of_request_resources(phy); | ||
218 | if (ret) | ||
219 | return ret; | ||
220 | } else if (pdata) { | ||
221 | ret = st33zp24_i2c_request_resources(client, phy); | ||
222 | if (ret) | ||
223 | return ret; | ||
224 | } | ||
225 | |||
226 | return st33zp24_probe(phy, &i2c_phy_ops, &client->dev, client->irq, | ||
227 | phy->io_lpcpd); | ||
228 | } | ||
229 | |||
230 | /* | ||
231 | * st33zp24_i2c_remove remove the TPM device | ||
232 | * @param: client, the i2c_client description (TPM I2C description). | ||
233 | * @return: 0 in case of success. | ||
234 | */ | ||
235 | static int st33zp24_i2c_remove(struct i2c_client *client) | ||
236 | { | ||
237 | struct tpm_chip *chip = i2c_get_clientdata(client); | ||
238 | |||
239 | return st33zp24_remove(chip); | ||
240 | } | ||
241 | |||
242 | static const struct i2c_device_id st33zp24_i2c_id[] = { | ||
243 | {TPM_ST33_I2C, 0}, | ||
244 | {} | ||
245 | }; | ||
246 | MODULE_DEVICE_TABLE(i2c, st33zp24_i2c_id); | ||
247 | |||
248 | #ifdef CONFIG_OF | ||
249 | static const struct of_device_id of_st33zp24_i2c_match[] = { | ||
250 | { .compatible = "st,st33zp24-i2c", }, | ||
251 | {} | ||
252 | }; | ||
253 | MODULE_DEVICE_TABLE(of, of_st33zp24_i2c_match); | ||
254 | #endif | ||
255 | |||
256 | static SIMPLE_DEV_PM_OPS(st33zp24_i2c_ops, st33zp24_pm_suspend, | ||
257 | st33zp24_pm_resume); | ||
258 | |||
259 | static struct i2c_driver st33zp24_i2c_driver = { | ||
260 | .driver = { | ||
261 | .owner = THIS_MODULE, | ||
262 | .name = TPM_ST33_I2C, | ||
263 | .pm = &st33zp24_i2c_ops, | ||
264 | .of_match_table = of_match_ptr(of_st33zp24_i2c_match), | ||
265 | }, | ||
266 | .probe = st33zp24_i2c_probe, | ||
267 | .remove = st33zp24_i2c_remove, | ||
268 | .id_table = st33zp24_i2c_id | ||
269 | }; | ||
270 | |||
271 | module_i2c_driver(st33zp24_i2c_driver); | ||
272 | |||
273 | MODULE_AUTHOR("TPM support (TPMsupport@list.st.com)"); | ||
274 | MODULE_DESCRIPTION("STM TPM 1.2 I2C ST33 Driver"); | ||
275 | MODULE_VERSION("1.3.0"); | ||
276 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/char/tpm/st33zp24/spi.c b/drivers/char/tpm/st33zp24/spi.c new file mode 100644 index 000000000000..f0184a1b0c1c --- /dev/null +++ b/drivers/char/tpm/st33zp24/spi.c | |||
@@ -0,0 +1,399 @@ | |||
1 | /* | ||
2 | * STMicroelectronics TPM SPI Linux driver for TPM ST33ZP24 | ||
3 | * Copyright (C) 2009 - 2015 STMicroelectronics | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/spi/spi.h> | ||
21 | #include <linux/gpio.h> | ||
22 | #include <linux/of_irq.h> | ||
23 | #include <linux/of_gpio.h> | ||
24 | #include <linux/tpm.h> | ||
25 | #include <linux/platform_data/st33zp24.h> | ||
26 | |||
27 | #include "st33zp24.h" | ||
28 | |||
29 | #define TPM_DATA_FIFO 0x24 | ||
30 | #define TPM_INTF_CAPABILITY 0x14 | ||
31 | |||
32 | #define TPM_DUMMY_BYTE 0x00 | ||
33 | |||
34 | #define MAX_SPI_LATENCY 15 | ||
35 | #define LOCALITY0 0 | ||
36 | |||
37 | #define ST33ZP24_OK 0x5A | ||
38 | #define ST33ZP24_UNDEFINED_ERR 0x80 | ||
39 | #define ST33ZP24_BADLOCALITY 0x81 | ||
40 | #define ST33ZP24_TISREGISTER_UKNOWN 0x82 | ||
41 | #define ST33ZP24_LOCALITY_NOT_ACTIVATED 0x83 | ||
42 | #define ST33ZP24_HASH_END_BEFORE_HASH_START 0x84 | ||
43 | #define ST33ZP24_BAD_COMMAND_ORDER 0x85 | ||
44 | #define ST33ZP24_INCORECT_RECEIVED_LENGTH 0x86 | ||
45 | #define ST33ZP24_TPM_FIFO_OVERFLOW 0x89 | ||
46 | #define ST33ZP24_UNEXPECTED_READ_FIFO 0x8A | ||
47 | #define ST33ZP24_UNEXPECTED_WRITE_FIFO 0x8B | ||
48 | #define ST33ZP24_CMDRDY_SET_WHEN_PROCESSING_HASH_END 0x90 | ||
49 | #define ST33ZP24_DUMMY_BYTES 0x00 | ||
50 | |||
51 | /* | ||
52 | * TPM command can be up to 2048 byte, A TPM response can be up to | ||
53 | * 1024 byte. | ||
54 | * Between command and response, there are latency byte (up to 15 | ||
55 | * usually on st33zp24 2 are enough). | ||
56 | * | ||
57 | * Overall when sending a command and expecting an answer we need if | ||
58 | * worst case: | ||
59 | * 2048 (for the TPM command) + 1024 (for the TPM answer). We need | ||
60 | * some latency byte before the answer is available (max 15). | ||
61 | * We have 2048 + 1024 + 15. | ||
62 | */ | ||
63 | #define ST33ZP24_SPI_BUFFER_SIZE (TPM_BUFSIZE + (TPM_BUFSIZE / 2) +\ | ||
64 | MAX_SPI_LATENCY) | ||
65 | |||
66 | |||
67 | struct st33zp24_spi_phy { | ||
68 | struct spi_device *spi_device; | ||
69 | struct spi_transfer spi_xfer; | ||
70 | u8 tx_buf[ST33ZP24_SPI_BUFFER_SIZE]; | ||
71 | u8 rx_buf[ST33ZP24_SPI_BUFFER_SIZE]; | ||
72 | |||
73 | int io_lpcpd; | ||
74 | int latency; | ||
75 | }; | ||
76 | |||
77 | static int st33zp24_status_to_errno(u8 code) | ||
78 | { | ||
79 | switch (code) { | ||
80 | case ST33ZP24_OK: | ||
81 | return 0; | ||
82 | case ST33ZP24_UNDEFINED_ERR: | ||
83 | case ST33ZP24_BADLOCALITY: | ||
84 | case ST33ZP24_TISREGISTER_UKNOWN: | ||
85 | case ST33ZP24_LOCALITY_NOT_ACTIVATED: | ||
86 | case ST33ZP24_HASH_END_BEFORE_HASH_START: | ||
87 | case ST33ZP24_BAD_COMMAND_ORDER: | ||
88 | case ST33ZP24_UNEXPECTED_READ_FIFO: | ||
89 | case ST33ZP24_UNEXPECTED_WRITE_FIFO: | ||
90 | case ST33ZP24_CMDRDY_SET_WHEN_PROCESSING_HASH_END: | ||
91 | return -EPROTO; | ||
92 | case ST33ZP24_INCORECT_RECEIVED_LENGTH: | ||
93 | case ST33ZP24_TPM_FIFO_OVERFLOW: | ||
94 | return -EMSGSIZE; | ||
95 | case ST33ZP24_DUMMY_BYTES: | ||
96 | return -ENOSYS; | ||
97 | } | ||
98 | return code; | ||
99 | } | ||
100 | |||
101 | /* | ||
102 | * st33zp24_spi_send | ||
103 | * Send byte to the TIS register according to the ST33ZP24 SPI protocol. | ||
104 | * @param: phy_id, the phy description | ||
105 | * @param: tpm_register, the tpm tis register where the data should be written | ||
106 | * @param: tpm_data, the tpm_data to write inside the tpm_register | ||
107 | * @param: tpm_size, The length of the data | ||
108 | * @return: should be zero if success else a negative error code. | ||
109 | */ | ||
110 | static int st33zp24_spi_send(void *phy_id, u8 tpm_register, u8 *tpm_data, | ||
111 | int tpm_size) | ||
112 | { | ||
113 | u8 data = 0; | ||
114 | int total_length = 0, nbr_dummy_bytes = 0, ret = 0; | ||
115 | struct st33zp24_spi_phy *phy = phy_id; | ||
116 | struct spi_device *dev = phy->spi_device; | ||
117 | u8 *tx_buf = (u8 *)phy->spi_xfer.tx_buf; | ||
118 | u8 *rx_buf = phy->spi_xfer.rx_buf; | ||
119 | |||
120 | /* Pre-Header */ | ||
121 | data = TPM_WRITE_DIRECTION | LOCALITY0; | ||
122 | memcpy(tx_buf + total_length, &data, sizeof(data)); | ||
123 | total_length++; | ||
124 | data = tpm_register; | ||
125 | memcpy(tx_buf + total_length, &data, sizeof(data)); | ||
126 | total_length++; | ||
127 | |||
128 | if (tpm_size > 0 && tpm_register == TPM_DATA_FIFO) { | ||
129 | tx_buf[total_length++] = tpm_size >> 8; | ||
130 | tx_buf[total_length++] = tpm_size; | ||
131 | } | ||
132 | |||
133 | memcpy(&tx_buf[total_length], tpm_data, tpm_size); | ||
134 | total_length += tpm_size; | ||
135 | |||
136 | nbr_dummy_bytes = phy->latency; | ||
137 | memset(&tx_buf[total_length], TPM_DUMMY_BYTE, nbr_dummy_bytes); | ||
138 | |||
139 | phy->spi_xfer.len = total_length + nbr_dummy_bytes; | ||
140 | |||
141 | ret = spi_sync_transfer(dev, &phy->spi_xfer, 1); | ||
142 | if (ret == 0) | ||
143 | ret = rx_buf[total_length + nbr_dummy_bytes - 1]; | ||
144 | |||
145 | return st33zp24_status_to_errno(ret); | ||
146 | } /* st33zp24_spi_send() */ | ||
147 | |||
148 | /* | ||
149 | * read8_recv | ||
150 | * Recv byte from the TIS register according to the ST33ZP24 SPI protocol. | ||
151 | * @param: phy_id, the phy description | ||
152 | * @param: tpm_register, the tpm tis register where the data should be read | ||
153 | * @param: tpm_data, the TPM response | ||
154 | * @param: tpm_size, tpm TPM response size to read. | ||
155 | * @return: should be zero if success else a negative error code. | ||
156 | */ | ||
157 | static int read8_reg(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size) | ||
158 | { | ||
159 | u8 data = 0; | ||
160 | int total_length = 0, nbr_dummy_bytes, ret; | ||
161 | struct st33zp24_spi_phy *phy = phy_id; | ||
162 | struct spi_device *dev = phy->spi_device; | ||
163 | u8 *tx_buf = (u8 *)phy->spi_xfer.tx_buf; | ||
164 | u8 *rx_buf = phy->spi_xfer.rx_buf; | ||
165 | |||
166 | /* Pre-Header */ | ||
167 | data = LOCALITY0; | ||
168 | memcpy(tx_buf + total_length, &data, sizeof(data)); | ||
169 | total_length++; | ||
170 | data = tpm_register; | ||
171 | memcpy(tx_buf + total_length, &data, sizeof(data)); | ||
172 | total_length++; | ||
173 | |||
174 | nbr_dummy_bytes = phy->latency; | ||
175 | memset(&tx_buf[total_length], TPM_DUMMY_BYTE, | ||
176 | nbr_dummy_bytes + tpm_size); | ||
177 | |||
178 | phy->spi_xfer.len = total_length + nbr_dummy_bytes + tpm_size; | ||
179 | |||
180 | /* header + status byte + size of the data + status byte */ | ||
181 | ret = spi_sync_transfer(dev, &phy->spi_xfer, 1); | ||
182 | if (tpm_size > 0 && ret == 0) { | ||
183 | ret = rx_buf[total_length + nbr_dummy_bytes - 1]; | ||
184 | |||
185 | memcpy(tpm_data, rx_buf + total_length + nbr_dummy_bytes, | ||
186 | tpm_size); | ||
187 | } | ||
188 | |||
189 | return ret; | ||
190 | } /* read8_reg() */ | ||
191 | |||
192 | /* | ||
193 | * st33zp24_spi_recv | ||
194 | * Recv byte from the TIS register according to the ST33ZP24 SPI protocol. | ||
195 | * @param: phy_id, the phy description | ||
196 | * @param: tpm_register, the tpm tis register where the data should be read | ||
197 | * @param: tpm_data, the TPM response | ||
198 | * @param: tpm_size, tpm TPM response size to read. | ||
199 | * @return: number of byte read successfully: should be one if success. | ||
200 | */ | ||
201 | static int st33zp24_spi_recv(void *phy_id, u8 tpm_register, u8 *tpm_data, | ||
202 | int tpm_size) | ||
203 | { | ||
204 | int ret; | ||
205 | |||
206 | ret = read8_reg(phy_id, tpm_register, tpm_data, tpm_size); | ||
207 | if (!st33zp24_status_to_errno(ret)) | ||
208 | return tpm_size; | ||
209 | return ret; | ||
210 | } /* st33zp24_spi_recv() */ | ||
211 | |||
212 | static int evaluate_latency(void *phy_id) | ||
213 | { | ||
214 | struct st33zp24_spi_phy *phy = phy_id; | ||
215 | int latency = 1, status = 0; | ||
216 | u8 data = 0; | ||
217 | |||
218 | while (!status && latency < MAX_SPI_LATENCY) { | ||
219 | phy->latency = latency; | ||
220 | status = read8_reg(phy_id, TPM_INTF_CAPABILITY, &data, 1); | ||
221 | latency++; | ||
222 | } | ||
223 | return latency - 1; | ||
224 | } /* evaluate_latency() */ | ||
225 | |||
226 | static const struct st33zp24_phy_ops spi_phy_ops = { | ||
227 | .send = st33zp24_spi_send, | ||
228 | .recv = st33zp24_spi_recv, | ||
229 | }; | ||
230 | |||
231 | #ifdef CONFIG_OF | ||
232 | static int tpm_stm_spi_of_request_resources(struct st33zp24_spi_phy *phy) | ||
233 | { | ||
234 | struct device_node *pp; | ||
235 | struct spi_device *dev = phy->spi_device; | ||
236 | int gpio; | ||
237 | int ret; | ||
238 | |||
239 | pp = dev->dev.of_node; | ||
240 | if (!pp) { | ||
241 | dev_err(&dev->dev, "No platform data\n"); | ||
242 | return -ENODEV; | ||
243 | } | ||
244 | |||
245 | /* Get GPIO from device tree */ | ||
246 | gpio = of_get_named_gpio(pp, "lpcpd-gpios", 0); | ||
247 | if (gpio < 0) { | ||
248 | dev_err(&dev->dev, | ||
249 | "Failed to retrieve lpcpd-gpios from dts.\n"); | ||
250 | phy->io_lpcpd = -1; | ||
251 | /* | ||
252 | * lpcpd pin is not specified. This is not an issue as | ||
253 | * power management can be also managed by TPM specific | ||
254 | * commands. So leave with a success status code. | ||
255 | */ | ||
256 | return 0; | ||
257 | } | ||
258 | /* GPIO request and configuration */ | ||
259 | ret = devm_gpio_request_one(&dev->dev, gpio, | ||
260 | GPIOF_OUT_INIT_HIGH, "TPM IO LPCPD"); | ||
261 | if (ret) { | ||
262 | dev_err(&dev->dev, "Failed to request lpcpd pin\n"); | ||
263 | return -ENODEV; | ||
264 | } | ||
265 | phy->io_lpcpd = gpio; | ||
266 | |||
267 | return 0; | ||
268 | } | ||
269 | #else | ||
270 | static int tpm_stm_spi_of_request_resources(struct st33zp24_spi_phy *phy) | ||
271 | { | ||
272 | return -ENODEV; | ||
273 | } | ||
274 | #endif | ||
275 | |||
276 | static int tpm_stm_spi_request_resources(struct spi_device *dev, | ||
277 | struct st33zp24_spi_phy *phy) | ||
278 | { | ||
279 | struct st33zp24_platform_data *pdata; | ||
280 | int ret; | ||
281 | |||
282 | pdata = dev->dev.platform_data; | ||
283 | if (!pdata) { | ||
284 | dev_err(&dev->dev, "No platform data\n"); | ||
285 | return -ENODEV; | ||
286 | } | ||
287 | |||
288 | /* store for late use */ | ||
289 | phy->io_lpcpd = pdata->io_lpcpd; | ||
290 | |||
291 | if (gpio_is_valid(pdata->io_lpcpd)) { | ||
292 | ret = devm_gpio_request_one(&dev->dev, | ||
293 | pdata->io_lpcpd, GPIOF_OUT_INIT_HIGH, | ||
294 | "TPM IO_LPCPD"); | ||
295 | if (ret) { | ||
296 | dev_err(&dev->dev, "%s : reset gpio_request failed\n", | ||
297 | __FILE__); | ||
298 | return ret; | ||
299 | } | ||
300 | } | ||
301 | |||
302 | return 0; | ||
303 | } | ||
304 | |||
305 | /* | ||
306 | * tpm_st33_spi_probe initialize the TPM device | ||
307 | * @param: dev, the spi_device drescription (TPM SPI description). | ||
308 | * @return: 0 in case of success. | ||
309 | * or a negative value describing the error. | ||
310 | */ | ||
311 | static int | ||
312 | tpm_st33_spi_probe(struct spi_device *dev) | ||
313 | { | ||
314 | int ret; | ||
315 | struct st33zp24_platform_data *pdata; | ||
316 | struct st33zp24_spi_phy *phy; | ||
317 | |||
318 | /* Check SPI platform functionnalities */ | ||
319 | if (!dev) { | ||
320 | pr_info("%s: dev is NULL. Device is not accessible.\n", | ||
321 | __func__); | ||
322 | return -ENODEV; | ||
323 | } | ||
324 | |||
325 | phy = devm_kzalloc(&dev->dev, sizeof(struct st33zp24_spi_phy), | ||
326 | GFP_KERNEL); | ||
327 | if (!phy) | ||
328 | return -ENOMEM; | ||
329 | |||
330 | phy->spi_device = dev; | ||
331 | pdata = dev->dev.platform_data; | ||
332 | if (!pdata && dev->dev.of_node) { | ||
333 | ret = tpm_stm_spi_of_request_resources(phy); | ||
334 | if (ret) | ||
335 | return ret; | ||
336 | } else if (pdata) { | ||
337 | ret = tpm_stm_spi_request_resources(dev, phy); | ||
338 | if (ret) | ||
339 | return ret; | ||
340 | } | ||
341 | |||
342 | phy->spi_xfer.tx_buf = phy->tx_buf; | ||
343 | phy->spi_xfer.rx_buf = phy->rx_buf; | ||
344 | |||
345 | phy->latency = evaluate_latency(phy); | ||
346 | if (phy->latency <= 0) | ||
347 | return -ENODEV; | ||
348 | |||
349 | return st33zp24_probe(phy, &spi_phy_ops, &dev->dev, dev->irq, | ||
350 | phy->io_lpcpd); | ||
351 | } | ||
352 | |||
353 | /* | ||
354 | * tpm_st33_spi_remove remove the TPM device | ||
355 | * @param: client, the spi_device drescription (TPM SPI description). | ||
356 | * @return: 0 in case of success. | ||
357 | */ | ||
358 | static int tpm_st33_spi_remove(struct spi_device *dev) | ||
359 | { | ||
360 | struct tpm_chip *chip = spi_get_drvdata(dev); | ||
361 | |||
362 | return st33zp24_remove(chip); | ||
363 | } | ||
364 | |||
365 | static const struct spi_device_id st33zp24_spi_id[] = { | ||
366 | {TPM_ST33_SPI, 0}, | ||
367 | {} | ||
368 | }; | ||
369 | MODULE_DEVICE_TABLE(spi, st33zp24_spi_id); | ||
370 | |||
371 | #ifdef CONFIG_OF | ||
372 | static const struct of_device_id of_st33zp24_spi_match[] = { | ||
373 | { .compatible = "st,st33zp24-spi", }, | ||
374 | {} | ||
375 | }; | ||
376 | MODULE_DEVICE_TABLE(of, of_st33zp24_spi_match); | ||
377 | #endif | ||
378 | |||
379 | static SIMPLE_DEV_PM_OPS(st33zp24_spi_ops, st33zp24_pm_suspend, | ||
380 | st33zp24_pm_resume); | ||
381 | |||
382 | static struct spi_driver tpm_st33_spi_driver = { | ||
383 | .driver = { | ||
384 | .owner = THIS_MODULE, | ||
385 | .name = TPM_ST33_SPI, | ||
386 | .pm = &st33zp24_spi_ops, | ||
387 | .of_match_table = of_match_ptr(of_st33zp24_spi_match), | ||
388 | }, | ||
389 | .probe = tpm_st33_spi_probe, | ||
390 | .remove = tpm_st33_spi_remove, | ||
391 | .id_table = st33zp24_spi_id, | ||
392 | }; | ||
393 | |||
394 | module_spi_driver(tpm_st33_spi_driver); | ||
395 | |||
396 | MODULE_AUTHOR("TPM support (TPMsupport@list.st.com)"); | ||
397 | MODULE_DESCRIPTION("STM TPM 1.2 SPI ST33 Driver"); | ||
398 | MODULE_VERSION("1.3.0"); | ||
399 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/char/tpm/st33zp24/st33zp24.c b/drivers/char/tpm/st33zp24/st33zp24.c new file mode 100644 index 000000000000..8d626784cd8d --- /dev/null +++ b/drivers/char/tpm/st33zp24/st33zp24.c | |||
@@ -0,0 +1,698 @@ | |||
1 | /* | ||
2 | * STMicroelectronics TPM Linux driver for TPM ST33ZP24 | ||
3 | * Copyright (C) 2009 - 2015 STMicroelectronics | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/fs.h> | ||
21 | #include <linux/miscdevice.h> | ||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/delay.h> | ||
24 | #include <linux/wait.h> | ||
25 | #include <linux/freezer.h> | ||
26 | #include <linux/string.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | #include <linux/gpio.h> | ||
29 | #include <linux/sched.h> | ||
30 | #include <linux/uaccess.h> | ||
31 | #include <linux/io.h> | ||
32 | #include <linux/slab.h> | ||
33 | |||
34 | #include "../tpm.h" | ||
35 | #include "st33zp24.h" | ||
36 | |||
37 | #define TPM_ACCESS 0x0 | ||
38 | #define TPM_STS 0x18 | ||
39 | #define TPM_DATA_FIFO 0x24 | ||
40 | #define TPM_INTF_CAPABILITY 0x14 | ||
41 | #define TPM_INT_STATUS 0x10 | ||
42 | #define TPM_INT_ENABLE 0x08 | ||
43 | |||
44 | #define LOCALITY0 0 | ||
45 | |||
46 | enum st33zp24_access { | ||
47 | TPM_ACCESS_VALID = 0x80, | ||
48 | TPM_ACCESS_ACTIVE_LOCALITY = 0x20, | ||
49 | TPM_ACCESS_REQUEST_PENDING = 0x04, | ||
50 | TPM_ACCESS_REQUEST_USE = 0x02, | ||
51 | }; | ||
52 | |||
53 | enum st33zp24_status { | ||
54 | TPM_STS_VALID = 0x80, | ||
55 | TPM_STS_COMMAND_READY = 0x40, | ||
56 | TPM_STS_GO = 0x20, | ||
57 | TPM_STS_DATA_AVAIL = 0x10, | ||
58 | TPM_STS_DATA_EXPECT = 0x08, | ||
59 | }; | ||
60 | |||
61 | enum st33zp24_int_flags { | ||
62 | TPM_GLOBAL_INT_ENABLE = 0x80, | ||
63 | TPM_INTF_CMD_READY_INT = 0x080, | ||
64 | TPM_INTF_FIFO_AVALAIBLE_INT = 0x040, | ||
65 | TPM_INTF_WAKE_UP_READY_INT = 0x020, | ||
66 | TPM_INTF_LOCALITY_CHANGE_INT = 0x004, | ||
67 | TPM_INTF_STS_VALID_INT = 0x002, | ||
68 | TPM_INTF_DATA_AVAIL_INT = 0x001, | ||
69 | }; | ||
70 | |||
71 | enum tis_defaults { | ||
72 | TIS_SHORT_TIMEOUT = 750, | ||
73 | TIS_LONG_TIMEOUT = 2000, | ||
74 | }; | ||
75 | |||
76 | struct st33zp24_dev { | ||
77 | struct tpm_chip *chip; | ||
78 | void *phy_id; | ||
79 | const struct st33zp24_phy_ops *ops; | ||
80 | u32 intrs; | ||
81 | int io_lpcpd; | ||
82 | }; | ||
83 | |||
84 | /* | ||
85 | * clear_interruption clear the pending interrupt. | ||
86 | * @param: tpm_dev, the tpm device device. | ||
87 | * @return: the interrupt status value. | ||
88 | */ | ||
89 | static u8 clear_interruption(struct st33zp24_dev *tpm_dev) | ||
90 | { | ||
91 | u8 interrupt; | ||
92 | |||
93 | tpm_dev->ops->recv(tpm_dev->phy_id, TPM_INT_STATUS, &interrupt, 1); | ||
94 | tpm_dev->ops->send(tpm_dev->phy_id, TPM_INT_STATUS, &interrupt, 1); | ||
95 | return interrupt; | ||
96 | } /* clear_interruption() */ | ||
97 | |||
98 | /* | ||
99 | * st33zp24_cancel, cancel the current command execution or | ||
100 | * set STS to COMMAND READY. | ||
101 | * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h | ||
102 | */ | ||
103 | static void st33zp24_cancel(struct tpm_chip *chip) | ||
104 | { | ||
105 | struct st33zp24_dev *tpm_dev; | ||
106 | u8 data; | ||
107 | |||
108 | tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip); | ||
109 | |||
110 | data = TPM_STS_COMMAND_READY; | ||
111 | tpm_dev->ops->send(tpm_dev->phy_id, TPM_STS, &data, 1); | ||
112 | } /* st33zp24_cancel() */ | ||
113 | |||
114 | /* | ||
115 | * st33zp24_status return the TPM_STS register | ||
116 | * @param: chip, the tpm chip description | ||
117 | * @return: the TPM_STS register value. | ||
118 | */ | ||
119 | static u8 st33zp24_status(struct tpm_chip *chip) | ||
120 | { | ||
121 | struct st33zp24_dev *tpm_dev; | ||
122 | u8 data; | ||
123 | |||
124 | tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip); | ||
125 | |||
126 | tpm_dev->ops->recv(tpm_dev->phy_id, TPM_STS, &data, 1); | ||
127 | return data; | ||
128 | } /* st33zp24_status() */ | ||
129 | |||
130 | /* | ||
131 | * check_locality if the locality is active | ||
132 | * @param: chip, the tpm chip description | ||
133 | * @return: the active locality or -EACCESS. | ||
134 | */ | ||
135 | static int check_locality(struct tpm_chip *chip) | ||
136 | { | ||
137 | struct st33zp24_dev *tpm_dev; | ||
138 | u8 data; | ||
139 | u8 status; | ||
140 | |||
141 | tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip); | ||
142 | |||
143 | status = tpm_dev->ops->recv(tpm_dev->phy_id, TPM_ACCESS, &data, 1); | ||
144 | if (status && (data & | ||
145 | (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) == | ||
146 | (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) | ||
147 | return chip->vendor.locality; | ||
148 | |||
149 | return -EACCES; | ||
150 | } /* check_locality() */ | ||
151 | |||
152 | /* | ||
153 | * request_locality request the TPM locality | ||
154 | * @param: chip, the chip description | ||
155 | * @return: the active locality or negative value. | ||
156 | */ | ||
157 | static int request_locality(struct tpm_chip *chip) | ||
158 | { | ||
159 | unsigned long stop; | ||
160 | long ret; | ||
161 | struct st33zp24_dev *tpm_dev; | ||
162 | u8 data; | ||
163 | |||
164 | if (check_locality(chip) == chip->vendor.locality) | ||
165 | return chip->vendor.locality; | ||
166 | |||
167 | tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip); | ||
168 | |||
169 | data = TPM_ACCESS_REQUEST_USE; | ||
170 | ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_ACCESS, &data, 1); | ||
171 | if (ret < 0) | ||
172 | return ret; | ||
173 | |||
174 | stop = jiffies + chip->vendor.timeout_a; | ||
175 | |||
176 | /* Request locality is usually effective after the request */ | ||
177 | do { | ||
178 | if (check_locality(chip) >= 0) | ||
179 | return chip->vendor.locality; | ||
180 | msleep(TPM_TIMEOUT); | ||
181 | } while (time_before(jiffies, stop)); | ||
182 | |||
183 | /* could not get locality */ | ||
184 | return -EACCES; | ||
185 | } /* request_locality() */ | ||
186 | |||
187 | /* | ||
188 | * release_locality release the active locality | ||
189 | * @param: chip, the tpm chip description. | ||
190 | */ | ||
191 | static void release_locality(struct tpm_chip *chip) | ||
192 | { | ||
193 | struct st33zp24_dev *tpm_dev; | ||
194 | u8 data; | ||
195 | |||
196 | tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip); | ||
197 | data = TPM_ACCESS_ACTIVE_LOCALITY; | ||
198 | |||
199 | tpm_dev->ops->send(tpm_dev->phy_id, TPM_ACCESS, &data, 1); | ||
200 | } | ||
201 | |||
202 | /* | ||
203 | * get_burstcount return the burstcount value | ||
204 | * @param: chip, the chip description | ||
205 | * return: the burstcount or negative value. | ||
206 | */ | ||
207 | static int get_burstcount(struct tpm_chip *chip) | ||
208 | { | ||
209 | unsigned long stop; | ||
210 | int burstcnt, status; | ||
211 | u8 tpm_reg, temp; | ||
212 | struct st33zp24_dev *tpm_dev; | ||
213 | |||
214 | tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip); | ||
215 | |||
216 | stop = jiffies + chip->vendor.timeout_d; | ||
217 | do { | ||
218 | tpm_reg = TPM_STS + 1; | ||
219 | status = tpm_dev->ops->recv(tpm_dev->phy_id, tpm_reg, &temp, 1); | ||
220 | if (status < 0) | ||
221 | return -EBUSY; | ||
222 | |||
223 | tpm_reg = TPM_STS + 2; | ||
224 | burstcnt = temp; | ||
225 | status = tpm_dev->ops->recv(tpm_dev->phy_id, tpm_reg, &temp, 1); | ||
226 | if (status < 0) | ||
227 | return -EBUSY; | ||
228 | |||
229 | burstcnt |= temp << 8; | ||
230 | if (burstcnt) | ||
231 | return burstcnt; | ||
232 | msleep(TPM_TIMEOUT); | ||
233 | } while (time_before(jiffies, stop)); | ||
234 | return -EBUSY; | ||
235 | } /* get_burstcount() */ | ||
236 | |||
237 | |||
238 | /* | ||
239 | * wait_for_tpm_stat_cond | ||
240 | * @param: chip, chip description | ||
241 | * @param: mask, expected mask value | ||
242 | * @param: check_cancel, does the command expected to be canceled ? | ||
243 | * @param: canceled, did we received a cancel request ? | ||
244 | * @return: true if status == mask or if the command is canceled. | ||
245 | * false in other cases. | ||
246 | */ | ||
247 | static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask, | ||
248 | bool check_cancel, bool *canceled) | ||
249 | { | ||
250 | u8 status = chip->ops->status(chip); | ||
251 | |||
252 | *canceled = false; | ||
253 | if ((status & mask) == mask) | ||
254 | return true; | ||
255 | if (check_cancel && chip->ops->req_canceled(chip, status)) { | ||
256 | *canceled = true; | ||
257 | return true; | ||
258 | } | ||
259 | return false; | ||
260 | } | ||
261 | |||
262 | /* | ||
263 | * wait_for_stat wait for a TPM_STS value | ||
264 | * @param: chip, the tpm chip description | ||
265 | * @param: mask, the value mask to wait | ||
266 | * @param: timeout, the timeout | ||
267 | * @param: queue, the wait queue. | ||
268 | * @param: check_cancel, does the command can be cancelled ? | ||
269 | * @return: the tpm status, 0 if success, -ETIME if timeout is reached. | ||
270 | */ | ||
271 | static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, | ||
272 | wait_queue_head_t *queue, bool check_cancel) | ||
273 | { | ||
274 | unsigned long stop; | ||
275 | int ret = 0; | ||
276 | bool canceled = false; | ||
277 | bool condition; | ||
278 | u32 cur_intrs; | ||
279 | u8 status; | ||
280 | struct st33zp24_dev *tpm_dev; | ||
281 | |||
282 | tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip); | ||
283 | |||
284 | /* check current status */ | ||
285 | status = st33zp24_status(chip); | ||
286 | if ((status & mask) == mask) | ||
287 | return 0; | ||
288 | |||
289 | stop = jiffies + timeout; | ||
290 | |||
291 | if (chip->vendor.irq) { | ||
292 | cur_intrs = tpm_dev->intrs; | ||
293 | clear_interruption(tpm_dev); | ||
294 | enable_irq(chip->vendor.irq); | ||
295 | |||
296 | do { | ||
297 | if (ret == -ERESTARTSYS && freezing(current)) | ||
298 | clear_thread_flag(TIF_SIGPENDING); | ||
299 | |||
300 | timeout = stop - jiffies; | ||
301 | if ((long) timeout <= 0) | ||
302 | return -1; | ||
303 | |||
304 | ret = wait_event_interruptible_timeout(*queue, | ||
305 | cur_intrs != tpm_dev->intrs, | ||
306 | timeout); | ||
307 | clear_interruption(tpm_dev); | ||
308 | condition = wait_for_tpm_stat_cond(chip, mask, | ||
309 | check_cancel, &canceled); | ||
310 | if (ret >= 0 && condition) { | ||
311 | if (canceled) | ||
312 | return -ECANCELED; | ||
313 | return 0; | ||
314 | } | ||
315 | } while (ret == -ERESTARTSYS && freezing(current)); | ||
316 | |||
317 | disable_irq_nosync(chip->vendor.irq); | ||
318 | |||
319 | } else { | ||
320 | do { | ||
321 | msleep(TPM_TIMEOUT); | ||
322 | status = chip->ops->status(chip); | ||
323 | if ((status & mask) == mask) | ||
324 | return 0; | ||
325 | } while (time_before(jiffies, stop)); | ||
326 | } | ||
327 | |||
328 | return -ETIME; | ||
329 | } /* wait_for_stat() */ | ||
330 | |||
331 | /* | ||
332 | * recv_data receive data | ||
333 | * @param: chip, the tpm chip description | ||
334 | * @param: buf, the buffer where the data are received | ||
335 | * @param: count, the number of data to receive | ||
336 | * @return: the number of bytes read from TPM FIFO. | ||
337 | */ | ||
338 | static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count) | ||
339 | { | ||
340 | int size = 0, burstcnt, len, ret; | ||
341 | struct st33zp24_dev *tpm_dev; | ||
342 | |||
343 | tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip); | ||
344 | |||
345 | while (size < count && | ||
346 | wait_for_stat(chip, | ||
347 | TPM_STS_DATA_AVAIL | TPM_STS_VALID, | ||
348 | chip->vendor.timeout_c, | ||
349 | &chip->vendor.read_queue, true) == 0) { | ||
350 | burstcnt = get_burstcount(chip); | ||
351 | if (burstcnt < 0) | ||
352 | return burstcnt; | ||
353 | len = min_t(int, burstcnt, count - size); | ||
354 | ret = tpm_dev->ops->recv(tpm_dev->phy_id, TPM_DATA_FIFO, | ||
355 | buf + size, len); | ||
356 | if (ret < 0) | ||
357 | return ret; | ||
358 | |||
359 | size += len; | ||
360 | } | ||
361 | return size; | ||
362 | } | ||
363 | |||
364 | /* | ||
365 | * tpm_ioserirq_handler the serirq irq handler | ||
366 | * @param: irq, the tpm chip description | ||
367 | * @param: dev_id, the description of the chip | ||
368 | * @return: the status of the handler. | ||
369 | */ | ||
370 | static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id) | ||
371 | { | ||
372 | struct tpm_chip *chip = dev_id; | ||
373 | struct st33zp24_dev *tpm_dev; | ||
374 | |||
375 | tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip); | ||
376 | |||
377 | tpm_dev->intrs++; | ||
378 | wake_up_interruptible(&chip->vendor.read_queue); | ||
379 | disable_irq_nosync(chip->vendor.irq); | ||
380 | |||
381 | return IRQ_HANDLED; | ||
382 | } /* tpm_ioserirq_handler() */ | ||
383 | |||
384 | /* | ||
385 | * st33zp24_send send TPM commands through the I2C bus. | ||
386 | * | ||
387 | * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h | ||
388 | * @param: buf, the buffer to send. | ||
389 | * @param: count, the number of bytes to send. | ||
390 | * @return: In case of success the number of bytes sent. | ||
391 | * In other case, a < 0 value describing the issue. | ||
392 | */ | ||
393 | static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf, | ||
394 | size_t len) | ||
395 | { | ||
396 | u32 status, i, size, ordinal; | ||
397 | int burstcnt = 0; | ||
398 | int ret; | ||
399 | u8 data; | ||
400 | struct st33zp24_dev *tpm_dev; | ||
401 | |||
402 | if (!chip) | ||
403 | return -EBUSY; | ||
404 | if (len < TPM_HEADER_SIZE) | ||
405 | return -EBUSY; | ||
406 | |||
407 | tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip); | ||
408 | |||
409 | ret = request_locality(chip); | ||
410 | if (ret < 0) | ||
411 | return ret; | ||
412 | |||
413 | status = st33zp24_status(chip); | ||
414 | if ((status & TPM_STS_COMMAND_READY) == 0) { | ||
415 | st33zp24_cancel(chip); | ||
416 | if (wait_for_stat | ||
417 | (chip, TPM_STS_COMMAND_READY, chip->vendor.timeout_b, | ||
418 | &chip->vendor.read_queue, false) < 0) { | ||
419 | ret = -ETIME; | ||
420 | goto out_err; | ||
421 | } | ||
422 | } | ||
423 | |||
424 | for (i = 0; i < len - 1;) { | ||
425 | burstcnt = get_burstcount(chip); | ||
426 | if (burstcnt < 0) | ||
427 | return burstcnt; | ||
428 | size = min_t(int, len - i - 1, burstcnt); | ||
429 | ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_DATA_FIFO, | ||
430 | buf + i, size); | ||
431 | if (ret < 0) | ||
432 | goto out_err; | ||
433 | |||
434 | i += size; | ||
435 | } | ||
436 | |||
437 | status = st33zp24_status(chip); | ||
438 | if ((status & TPM_STS_DATA_EXPECT) == 0) { | ||
439 | ret = -EIO; | ||
440 | goto out_err; | ||
441 | } | ||
442 | |||
443 | ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_DATA_FIFO, | ||
444 | buf + len - 1, 1); | ||
445 | if (ret < 0) | ||
446 | goto out_err; | ||
447 | |||
448 | status = st33zp24_status(chip); | ||
449 | if ((status & TPM_STS_DATA_EXPECT) != 0) { | ||
450 | ret = -EIO; | ||
451 | goto out_err; | ||
452 | } | ||
453 | |||
454 | data = TPM_STS_GO; | ||
455 | ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_STS, &data, 1); | ||
456 | if (ret < 0) | ||
457 | goto out_err; | ||
458 | |||
459 | if (chip->vendor.irq) { | ||
460 | ordinal = be32_to_cpu(*((__be32 *) (buf + 6))); | ||
461 | |||
462 | ret = wait_for_stat(chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID, | ||
463 | tpm_calc_ordinal_duration(chip, ordinal), | ||
464 | &chip->vendor.read_queue, false); | ||
465 | if (ret < 0) | ||
466 | goto out_err; | ||
467 | } | ||
468 | |||
469 | return len; | ||
470 | out_err: | ||
471 | st33zp24_cancel(chip); | ||
472 | release_locality(chip); | ||
473 | return ret; | ||
474 | } | ||
475 | |||
476 | /* | ||
477 | * st33zp24_recv received TPM response through TPM phy. | ||
478 | * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h. | ||
479 | * @param: buf, the buffer to store datas. | ||
480 | * @param: count, the number of bytes to send. | ||
481 | * @return: In case of success the number of bytes received. | ||
482 | * In other case, a < 0 value describing the issue. | ||
483 | */ | ||
484 | static int st33zp24_recv(struct tpm_chip *chip, unsigned char *buf, | ||
485 | size_t count) | ||
486 | { | ||
487 | int size = 0; | ||
488 | int expected; | ||
489 | |||
490 | if (!chip) | ||
491 | return -EBUSY; | ||
492 | |||
493 | if (count < TPM_HEADER_SIZE) { | ||
494 | size = -EIO; | ||
495 | goto out; | ||
496 | } | ||
497 | |||
498 | size = recv_data(chip, buf, TPM_HEADER_SIZE); | ||
499 | if (size < TPM_HEADER_SIZE) { | ||
500 | dev_err(&chip->dev, "Unable to read header\n"); | ||
501 | goto out; | ||
502 | } | ||
503 | |||
504 | expected = be32_to_cpu(*(__be32 *)(buf + 2)); | ||
505 | if (expected > count) { | ||
506 | size = -EIO; | ||
507 | goto out; | ||
508 | } | ||
509 | |||
510 | size += recv_data(chip, &buf[TPM_HEADER_SIZE], | ||
511 | expected - TPM_HEADER_SIZE); | ||
512 | if (size < expected) { | ||
513 | dev_err(&chip->dev, "Unable to read remainder of result\n"); | ||
514 | size = -ETIME; | ||
515 | } | ||
516 | |||
517 | out: | ||
518 | st33zp24_cancel(chip); | ||
519 | release_locality(chip); | ||
520 | return size; | ||
521 | } | ||
522 | |||
523 | /* | ||
524 | * st33zp24_req_canceled | ||
525 | * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h. | ||
526 | * @param: status, the TPM status. | ||
527 | * @return: Does TPM ready to compute a new command ? true. | ||
528 | */ | ||
529 | static bool st33zp24_req_canceled(struct tpm_chip *chip, u8 status) | ||
530 | { | ||
531 | return (status == TPM_STS_COMMAND_READY); | ||
532 | } | ||
533 | |||
534 | static const struct tpm_class_ops st33zp24_tpm = { | ||
535 | .send = st33zp24_send, | ||
536 | .recv = st33zp24_recv, | ||
537 | .cancel = st33zp24_cancel, | ||
538 | .status = st33zp24_status, | ||
539 | .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID, | ||
540 | .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, | ||
541 | .req_canceled = st33zp24_req_canceled, | ||
542 | }; | ||
543 | |||
544 | /* | ||
545 | * st33zp24_probe initialize the TPM device | ||
546 | * @param: client, the i2c_client drescription (TPM I2C description). | ||
547 | * @param: id, the i2c_device_id struct. | ||
548 | * @return: 0 in case of success. | ||
549 | * -1 in other case. | ||
550 | */ | ||
551 | int st33zp24_probe(void *phy_id, const struct st33zp24_phy_ops *ops, | ||
552 | struct device *dev, int irq, int io_lpcpd) | ||
553 | { | ||
554 | int ret; | ||
555 | u8 intmask = 0; | ||
556 | struct tpm_chip *chip; | ||
557 | struct st33zp24_dev *tpm_dev; | ||
558 | |||
559 | chip = tpmm_chip_alloc(dev, &st33zp24_tpm); | ||
560 | if (IS_ERR(chip)) | ||
561 | return PTR_ERR(chip); | ||
562 | |||
563 | tpm_dev = devm_kzalloc(dev, sizeof(struct st33zp24_dev), | ||
564 | GFP_KERNEL); | ||
565 | if (!tpm_dev) | ||
566 | return -ENOMEM; | ||
567 | |||
568 | TPM_VPRIV(chip) = tpm_dev; | ||
569 | tpm_dev->phy_id = phy_id; | ||
570 | tpm_dev->ops = ops; | ||
571 | |||
572 | chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT); | ||
573 | chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT); | ||
574 | chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT); | ||
575 | chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT); | ||
576 | |||
577 | chip->vendor.locality = LOCALITY0; | ||
578 | |||
579 | if (irq) { | ||
580 | /* INTERRUPT Setup */ | ||
581 | init_waitqueue_head(&chip->vendor.read_queue); | ||
582 | tpm_dev->intrs = 0; | ||
583 | |||
584 | if (request_locality(chip) != LOCALITY0) { | ||
585 | ret = -ENODEV; | ||
586 | goto _tpm_clean_answer; | ||
587 | } | ||
588 | |||
589 | clear_interruption(tpm_dev); | ||
590 | ret = devm_request_irq(dev, irq, tpm_ioserirq_handler, | ||
591 | IRQF_TRIGGER_HIGH, "TPM SERIRQ management", | ||
592 | chip); | ||
593 | if (ret < 0) { | ||
594 | dev_err(&chip->dev, "TPM SERIRQ signals %d not available\n", | ||
595 | irq); | ||
596 | goto _tpm_clean_answer; | ||
597 | } | ||
598 | |||
599 | intmask |= TPM_INTF_CMD_READY_INT | ||
600 | | TPM_INTF_STS_VALID_INT | ||
601 | | TPM_INTF_DATA_AVAIL_INT; | ||
602 | |||
603 | ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_INT_ENABLE, | ||
604 | &intmask, 1); | ||
605 | if (ret < 0) | ||
606 | goto _tpm_clean_answer; | ||
607 | |||
608 | intmask = TPM_GLOBAL_INT_ENABLE; | ||
609 | ret = tpm_dev->ops->send(tpm_dev->phy_id, (TPM_INT_ENABLE + 3), | ||
610 | &intmask, 1); | ||
611 | if (ret < 0) | ||
612 | goto _tpm_clean_answer; | ||
613 | |||
614 | chip->vendor.irq = irq; | ||
615 | |||
616 | disable_irq_nosync(chip->vendor.irq); | ||
617 | |||
618 | tpm_gen_interrupt(chip); | ||
619 | } | ||
620 | |||
621 | tpm_get_timeouts(chip); | ||
622 | tpm_do_selftest(chip); | ||
623 | |||
624 | return tpm_chip_register(chip); | ||
625 | _tpm_clean_answer: | ||
626 | dev_info(&chip->dev, "TPM initialization fail\n"); | ||
627 | return ret; | ||
628 | } | ||
629 | EXPORT_SYMBOL(st33zp24_probe); | ||
630 | |||
631 | /* | ||
632 | * st33zp24_remove remove the TPM device | ||
633 | * @param: tpm_data, the tpm phy. | ||
634 | * @return: 0 in case of success. | ||
635 | */ | ||
636 | int st33zp24_remove(struct tpm_chip *chip) | ||
637 | { | ||
638 | tpm_chip_unregister(chip); | ||
639 | return 0; | ||
640 | } | ||
641 | EXPORT_SYMBOL(st33zp24_remove); | ||
642 | |||
643 | #ifdef CONFIG_PM_SLEEP | ||
644 | /* | ||
645 | * st33zp24_pm_suspend suspend the TPM device | ||
646 | * @param: tpm_data, the tpm phy. | ||
647 | * @param: mesg, the power management message. | ||
648 | * @return: 0 in case of success. | ||
649 | */ | ||
650 | int st33zp24_pm_suspend(struct device *dev) | ||
651 | { | ||
652 | struct tpm_chip *chip = dev_get_drvdata(dev); | ||
653 | struct st33zp24_dev *tpm_dev; | ||
654 | int ret = 0; | ||
655 | |||
656 | tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip); | ||
657 | |||
658 | if (gpio_is_valid(tpm_dev->io_lpcpd)) | ||
659 | gpio_set_value(tpm_dev->io_lpcpd, 0); | ||
660 | else | ||
661 | ret = tpm_pm_suspend(dev); | ||
662 | |||
663 | return ret; | ||
664 | } /* st33zp24_pm_suspend() */ | ||
665 | EXPORT_SYMBOL(st33zp24_pm_suspend); | ||
666 | |||
667 | /* | ||
668 | * st33zp24_pm_resume resume the TPM device | ||
669 | * @param: tpm_data, the tpm phy. | ||
670 | * @return: 0 in case of success. | ||
671 | */ | ||
672 | int st33zp24_pm_resume(struct device *dev) | ||
673 | { | ||
674 | struct tpm_chip *chip = dev_get_drvdata(dev); | ||
675 | struct st33zp24_dev *tpm_dev; | ||
676 | int ret = 0; | ||
677 | |||
678 | tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip); | ||
679 | |||
680 | if (gpio_is_valid(tpm_dev->io_lpcpd)) { | ||
681 | gpio_set_value(tpm_dev->io_lpcpd, 1); | ||
682 | ret = wait_for_stat(chip, | ||
683 | TPM_STS_VALID, chip->vendor.timeout_b, | ||
684 | &chip->vendor.read_queue, false); | ||
685 | } else { | ||
686 | ret = tpm_pm_resume(dev); | ||
687 | if (!ret) | ||
688 | tpm_do_selftest(chip); | ||
689 | } | ||
690 | return ret; | ||
691 | } /* st33zp24_pm_resume() */ | ||
692 | EXPORT_SYMBOL(st33zp24_pm_resume); | ||
693 | #endif | ||
694 | |||
695 | MODULE_AUTHOR("TPM support (TPMsupport@list.st.com)"); | ||
696 | MODULE_DESCRIPTION("ST33ZP24 TPM 1.2 driver"); | ||
697 | MODULE_VERSION("1.3.0"); | ||
698 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/char/tpm/st33zp24/st33zp24.h b/drivers/char/tpm/st33zp24/st33zp24.h new file mode 100644 index 000000000000..c207cebf67dd --- /dev/null +++ b/drivers/char/tpm/st33zp24/st33zp24.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * STMicroelectronics TPM Linux driver for TPM ST33ZP24 | ||
3 | * Copyright (C) 2009 - 2015 STMicroelectronics | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #ifndef __LOCAL_ST33ZP24_H__ | ||
19 | #define __LOCAL_ST33ZP24_H__ | ||
20 | |||
21 | #define TPM_WRITE_DIRECTION 0x80 | ||
22 | #define TPM_BUFSIZE 2048 | ||
23 | |||
24 | struct st33zp24_phy_ops { | ||
25 | int (*send)(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size); | ||
26 | int (*recv)(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size); | ||
27 | }; | ||
28 | |||
29 | #ifdef CONFIG_PM_SLEEP | ||
30 | int st33zp24_pm_suspend(struct device *dev); | ||
31 | int st33zp24_pm_resume(struct device *dev); | ||
32 | #endif | ||
33 | |||
34 | int st33zp24_probe(void *phy_id, const struct st33zp24_phy_ops *ops, | ||
35 | struct device *dev, int irq, int io_lpcpd); | ||
36 | int st33zp24_remove(struct tpm_chip *chip); | ||
37 | #endif /* __LOCAL_ST33ZP24_H__ */ | ||
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index e096e9cddb40..283f00a7f036 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c | |||
@@ -170,6 +170,41 @@ static void tpm_dev_del_device(struct tpm_chip *chip) | |||
170 | device_unregister(&chip->dev); | 170 | device_unregister(&chip->dev); |
171 | } | 171 | } |
172 | 172 | ||
173 | static int tpm1_chip_register(struct tpm_chip *chip) | ||
174 | { | ||
175 | int rc; | ||
176 | |||
177 | if (chip->flags & TPM_CHIP_FLAG_TPM2) | ||
178 | return 0; | ||
179 | |||
180 | rc = tpm_sysfs_add_device(chip); | ||
181 | if (rc) | ||
182 | return rc; | ||
183 | |||
184 | rc = tpm_add_ppi(chip); | ||
185 | if (rc) { | ||
186 | tpm_sysfs_del_device(chip); | ||
187 | return rc; | ||
188 | } | ||
189 | |||
190 | chip->bios_dir = tpm_bios_log_setup(chip->devname); | ||
191 | |||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | static void tpm1_chip_unregister(struct tpm_chip *chip) | ||
196 | { | ||
197 | if (chip->flags & TPM_CHIP_FLAG_TPM2) | ||
198 | return; | ||
199 | |||
200 | if (chip->bios_dir) | ||
201 | tpm_bios_log_teardown(chip->bios_dir); | ||
202 | |||
203 | tpm_remove_ppi(chip); | ||
204 | |||
205 | tpm_sysfs_del_device(chip); | ||
206 | } | ||
207 | |||
173 | /* | 208 | /* |
174 | * tpm_chip_register() - create a character device for the TPM chip | 209 | * tpm_chip_register() - create a character device for the TPM chip |
175 | * @chip: TPM chip to use. | 210 | * @chip: TPM chip to use. |
@@ -185,22 +220,13 @@ int tpm_chip_register(struct tpm_chip *chip) | |||
185 | { | 220 | { |
186 | int rc; | 221 | int rc; |
187 | 222 | ||
188 | /* Populate sysfs for TPM1 devices. */ | 223 | rc = tpm1_chip_register(chip); |
189 | if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { | 224 | if (rc) |
190 | rc = tpm_sysfs_add_device(chip); | 225 | return rc; |
191 | if (rc) | ||
192 | goto del_misc; | ||
193 | |||
194 | rc = tpm_add_ppi(chip); | ||
195 | if (rc) | ||
196 | goto del_sysfs; | ||
197 | |||
198 | chip->bios_dir = tpm_bios_log_setup(chip->devname); | ||
199 | } | ||
200 | 226 | ||
201 | rc = tpm_dev_add_device(chip); | 227 | rc = tpm_dev_add_device(chip); |
202 | if (rc) | 228 | if (rc) |
203 | return rc; | 229 | goto out_err; |
204 | 230 | ||
205 | /* Make the chip available. */ | 231 | /* Make the chip available. */ |
206 | spin_lock(&driver_lock); | 232 | spin_lock(&driver_lock); |
@@ -210,10 +236,8 @@ int tpm_chip_register(struct tpm_chip *chip) | |||
210 | chip->flags |= TPM_CHIP_FLAG_REGISTERED; | 236 | chip->flags |= TPM_CHIP_FLAG_REGISTERED; |
211 | 237 | ||
212 | return 0; | 238 | return 0; |
213 | del_sysfs: | 239 | out_err: |
214 | tpm_sysfs_del_device(chip); | 240 | tpm1_chip_unregister(chip); |
215 | del_misc: | ||
216 | tpm_dev_del_device(chip); | ||
217 | return rc; | 241 | return rc; |
218 | } | 242 | } |
219 | EXPORT_SYMBOL_GPL(tpm_chip_register); | 243 | EXPORT_SYMBOL_GPL(tpm_chip_register); |
@@ -238,13 +262,7 @@ void tpm_chip_unregister(struct tpm_chip *chip) | |||
238 | spin_unlock(&driver_lock); | 262 | spin_unlock(&driver_lock); |
239 | synchronize_rcu(); | 263 | synchronize_rcu(); |
240 | 264 | ||
241 | if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { | 265 | tpm1_chip_unregister(chip); |
242 | if (chip->bios_dir) | ||
243 | tpm_bios_log_teardown(chip->bios_dir); | ||
244 | tpm_remove_ppi(chip); | ||
245 | tpm_sysfs_del_device(chip); | ||
246 | } | ||
247 | |||
248 | tpm_dev_del_device(chip); | 266 | tpm_dev_del_device(chip); |
249 | } | 267 | } |
250 | EXPORT_SYMBOL_GPL(tpm_chip_unregister); | 268 | EXPORT_SYMBOL_GPL(tpm_chip_unregister); |
diff --git a/drivers/char/tpm/tpm_i2c_stm_st33.c b/drivers/char/tpm/tpm_i2c_stm_st33.c deleted file mode 100644 index 612845b36c29..000000000000 --- a/drivers/char/tpm/tpm_i2c_stm_st33.c +++ /dev/null | |||
@@ -1,911 +0,0 @@ | |||
1 | /* | ||
2 | * STMicroelectronics TPM I2C Linux driver for TPM ST33ZP24 | ||
3 | * Copyright (C) 2009, 2010, 2014 STMicroelectronics | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
17 | * | ||
18 | * STMicroelectronics version 1.2.1, Copyright (C) 2014 | ||
19 | * STMicroelectronics comes with ABSOLUTELY NO WARRANTY. | ||
20 | * This is free software, and you are welcome to redistribute it | ||
21 | * under certain conditions. | ||
22 | * | ||
23 | * @Author: Christophe RICARD tpmsupport@st.com | ||
24 | * | ||
25 | * @File: tpm_stm_st33_i2c.c | ||
26 | * | ||
27 | * @Synopsis: | ||
28 | * 09/15/2010: First shot driver tpm_tis driver for | ||
29 | * lpc is used as model. | ||
30 | */ | ||
31 | |||
32 | #include <linux/pci.h> | ||
33 | #include <linux/module.h> | ||
34 | #include <linux/platform_device.h> | ||
35 | #include <linux/i2c.h> | ||
36 | #include <linux/fs.h> | ||
37 | #include <linux/miscdevice.h> | ||
38 | #include <linux/kernel.h> | ||
39 | #include <linux/delay.h> | ||
40 | #include <linux/wait.h> | ||
41 | #include <linux/freezer.h> | ||
42 | #include <linux/string.h> | ||
43 | #include <linux/interrupt.h> | ||
44 | #include <linux/sysfs.h> | ||
45 | #include <linux/gpio.h> | ||
46 | #include <linux/sched.h> | ||
47 | #include <linux/uaccess.h> | ||
48 | #include <linux/io.h> | ||
49 | #include <linux/slab.h> | ||
50 | #include <linux/of_irq.h> | ||
51 | #include <linux/of_gpio.h> | ||
52 | |||
53 | #include <linux/platform_data/tpm_stm_st33.h> | ||
54 | #include "tpm.h" | ||
55 | |||
56 | #define TPM_ACCESS 0x0 | ||
57 | #define TPM_STS 0x18 | ||
58 | #define TPM_HASH_END 0x20 | ||
59 | #define TPM_DATA_FIFO 0x24 | ||
60 | #define TPM_HASH_DATA 0x24 | ||
61 | #define TPM_HASH_START 0x28 | ||
62 | #define TPM_INTF_CAPABILITY 0x14 | ||
63 | #define TPM_INT_STATUS 0x10 | ||
64 | #define TPM_INT_ENABLE 0x08 | ||
65 | |||
66 | #define TPM_DUMMY_BYTE 0xAA | ||
67 | #define TPM_WRITE_DIRECTION 0x80 | ||
68 | #define TPM_HEADER_SIZE 10 | ||
69 | #define TPM_BUFSIZE 2048 | ||
70 | |||
71 | #define LOCALITY0 0 | ||
72 | |||
73 | |||
74 | enum stm33zp24_access { | ||
75 | TPM_ACCESS_VALID = 0x80, | ||
76 | TPM_ACCESS_ACTIVE_LOCALITY = 0x20, | ||
77 | TPM_ACCESS_REQUEST_PENDING = 0x04, | ||
78 | TPM_ACCESS_REQUEST_USE = 0x02, | ||
79 | }; | ||
80 | |||
81 | enum stm33zp24_status { | ||
82 | TPM_STS_VALID = 0x80, | ||
83 | TPM_STS_COMMAND_READY = 0x40, | ||
84 | TPM_STS_GO = 0x20, | ||
85 | TPM_STS_DATA_AVAIL = 0x10, | ||
86 | TPM_STS_DATA_EXPECT = 0x08, | ||
87 | }; | ||
88 | |||
89 | enum stm33zp24_int_flags { | ||
90 | TPM_GLOBAL_INT_ENABLE = 0x80, | ||
91 | TPM_INTF_CMD_READY_INT = 0x080, | ||
92 | TPM_INTF_FIFO_AVALAIBLE_INT = 0x040, | ||
93 | TPM_INTF_WAKE_UP_READY_INT = 0x020, | ||
94 | TPM_INTF_LOCALITY_CHANGE_INT = 0x004, | ||
95 | TPM_INTF_STS_VALID_INT = 0x002, | ||
96 | TPM_INTF_DATA_AVAIL_INT = 0x001, | ||
97 | }; | ||
98 | |||
99 | enum tis_defaults { | ||
100 | TIS_SHORT_TIMEOUT = 750, | ||
101 | TIS_LONG_TIMEOUT = 2000, | ||
102 | }; | ||
103 | |||
104 | struct tpm_stm_dev { | ||
105 | struct i2c_client *client; | ||
106 | struct tpm_chip *chip; | ||
107 | u8 buf[TPM_BUFSIZE + 1]; | ||
108 | u32 intrs; | ||
109 | int io_lpcpd; | ||
110 | }; | ||
111 | |||
112 | /* | ||
113 | * write8_reg | ||
114 | * Send byte to the TIS register according to the ST33ZP24 I2C protocol. | ||
115 | * @param: tpm_register, the tpm tis register where the data should be written | ||
116 | * @param: tpm_data, the tpm_data to write inside the tpm_register | ||
117 | * @param: tpm_size, The length of the data | ||
118 | * @return: Returns negative errno, or else the number of bytes written. | ||
119 | */ | ||
120 | static int write8_reg(struct tpm_stm_dev *tpm_dev, u8 tpm_register, | ||
121 | u8 *tpm_data, u16 tpm_size) | ||
122 | { | ||
123 | tpm_dev->buf[0] = tpm_register; | ||
124 | memcpy(tpm_dev->buf + 1, tpm_data, tpm_size); | ||
125 | return i2c_master_send(tpm_dev->client, tpm_dev->buf, tpm_size + 1); | ||
126 | } /* write8_reg() */ | ||
127 | |||
128 | /* | ||
129 | * read8_reg | ||
130 | * Recv byte from the TIS register according to the ST33ZP24 I2C protocol. | ||
131 | * @param: tpm_register, the tpm tis register where the data should be read | ||
132 | * @param: tpm_data, the TPM response | ||
133 | * @param: tpm_size, tpm TPM response size to read. | ||
134 | * @return: number of byte read successfully: should be one if success. | ||
135 | */ | ||
136 | static int read8_reg(struct tpm_stm_dev *tpm_dev, u8 tpm_register, | ||
137 | u8 *tpm_data, int tpm_size) | ||
138 | { | ||
139 | u8 status = 0; | ||
140 | u8 data; | ||
141 | |||
142 | data = TPM_DUMMY_BYTE; | ||
143 | status = write8_reg(tpm_dev, tpm_register, &data, 1); | ||
144 | if (status == 2) | ||
145 | status = i2c_master_recv(tpm_dev->client, tpm_data, tpm_size); | ||
146 | return status; | ||
147 | } /* read8_reg() */ | ||
148 | |||
149 | /* | ||
150 | * I2C_WRITE_DATA | ||
151 | * Send byte to the TIS register according to the ST33ZP24 I2C protocol. | ||
152 | * @param: tpm_dev, the chip description | ||
153 | * @param: tpm_register, the tpm tis register where the data should be written | ||
154 | * @param: tpm_data, the tpm_data to write inside the tpm_register | ||
155 | * @param: tpm_size, The length of the data | ||
156 | * @return: number of byte written successfully: should be one if success. | ||
157 | */ | ||
158 | #define I2C_WRITE_DATA(tpm_dev, tpm_register, tpm_data, tpm_size) \ | ||
159 | (write8_reg(tpm_dev, tpm_register | \ | ||
160 | TPM_WRITE_DIRECTION, tpm_data, tpm_size)) | ||
161 | |||
162 | /* | ||
163 | * I2C_READ_DATA | ||
164 | * Recv byte from the TIS register according to the ST33ZP24 I2C protocol. | ||
165 | * @param: tpm_dev, the chip description | ||
166 | * @param: tpm_register, the tpm tis register where the data should be read | ||
167 | * @param: tpm_data, the TPM response | ||
168 | * @param: tpm_size, tpm TPM response size to read. | ||
169 | * @return: number of byte read successfully: should be one if success. | ||
170 | */ | ||
171 | #define I2C_READ_DATA(tpm_dev, tpm_register, tpm_data, tpm_size) \ | ||
172 | (read8_reg(tpm_dev, tpm_register, tpm_data, tpm_size)) | ||
173 | |||
174 | /* | ||
175 | * clear_interruption | ||
176 | * clear the TPM interrupt register. | ||
177 | * @param: tpm, the chip description | ||
178 | * @return: the TPM_INT_STATUS value | ||
179 | */ | ||
180 | static u8 clear_interruption(struct tpm_stm_dev *tpm_dev) | ||
181 | { | ||
182 | u8 interrupt; | ||
183 | |||
184 | I2C_READ_DATA(tpm_dev, TPM_INT_STATUS, &interrupt, 1); | ||
185 | I2C_WRITE_DATA(tpm_dev, TPM_INT_STATUS, &interrupt, 1); | ||
186 | return interrupt; | ||
187 | } /* clear_interruption() */ | ||
188 | |||
189 | /* | ||
190 | * tpm_stm_i2c_cancel, cancel is not implemented. | ||
191 | * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h | ||
192 | */ | ||
193 | static void tpm_stm_i2c_cancel(struct tpm_chip *chip) | ||
194 | { | ||
195 | struct tpm_stm_dev *tpm_dev; | ||
196 | u8 data; | ||
197 | |||
198 | tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip); | ||
199 | |||
200 | data = TPM_STS_COMMAND_READY; | ||
201 | I2C_WRITE_DATA(tpm_dev, TPM_STS, &data, 1); | ||
202 | } /* tpm_stm_i2c_cancel() */ | ||
203 | |||
204 | /* | ||
205 | * tpm_stm_spi_status return the TPM_STS register | ||
206 | * @param: chip, the tpm chip description | ||
207 | * @return: the TPM_STS register value. | ||
208 | */ | ||
209 | static u8 tpm_stm_i2c_status(struct tpm_chip *chip) | ||
210 | { | ||
211 | struct tpm_stm_dev *tpm_dev; | ||
212 | u8 data; | ||
213 | |||
214 | tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip); | ||
215 | |||
216 | I2C_READ_DATA(tpm_dev, TPM_STS, &data, 1); | ||
217 | return data; | ||
218 | } /* tpm_stm_i2c_status() */ | ||
219 | |||
220 | |||
221 | /* | ||
222 | * check_locality if the locality is active | ||
223 | * @param: chip, the tpm chip description | ||
224 | * @return: the active locality or -EACCESS. | ||
225 | */ | ||
226 | static int check_locality(struct tpm_chip *chip) | ||
227 | { | ||
228 | struct tpm_stm_dev *tpm_dev; | ||
229 | u8 data; | ||
230 | u8 status; | ||
231 | |||
232 | tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip); | ||
233 | |||
234 | status = I2C_READ_DATA(tpm_dev, TPM_ACCESS, &data, 1); | ||
235 | if (status && (data & | ||
236 | (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) == | ||
237 | (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) | ||
238 | return chip->vendor.locality; | ||
239 | |||
240 | return -EACCES; | ||
241 | } /* check_locality() */ | ||
242 | |||
243 | /* | ||
244 | * request_locality request the TPM locality | ||
245 | * @param: chip, the chip description | ||
246 | * @return: the active locality or EACCESS. | ||
247 | */ | ||
248 | static int request_locality(struct tpm_chip *chip) | ||
249 | { | ||
250 | unsigned long stop; | ||
251 | long ret; | ||
252 | struct tpm_stm_dev *tpm_dev; | ||
253 | u8 data; | ||
254 | |||
255 | if (check_locality(chip) == chip->vendor.locality) | ||
256 | return chip->vendor.locality; | ||
257 | |||
258 | tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip); | ||
259 | |||
260 | data = TPM_ACCESS_REQUEST_USE; | ||
261 | ret = I2C_WRITE_DATA(tpm_dev, TPM_ACCESS, &data, 1); | ||
262 | if (ret < 0) | ||
263 | goto end; | ||
264 | |||
265 | stop = jiffies + chip->vendor.timeout_a; | ||
266 | |||
267 | /* Request locality is usually effective after the request */ | ||
268 | do { | ||
269 | if (check_locality(chip) >= 0) | ||
270 | return chip->vendor.locality; | ||
271 | msleep(TPM_TIMEOUT); | ||
272 | } while (time_before(jiffies, stop)); | ||
273 | ret = -EACCES; | ||
274 | end: | ||
275 | return ret; | ||
276 | } /* request_locality() */ | ||
277 | |||
278 | /* | ||
279 | * release_locality release the active locality | ||
280 | * @param: chip, the tpm chip description. | ||
281 | */ | ||
282 | static void release_locality(struct tpm_chip *chip) | ||
283 | { | ||
284 | struct tpm_stm_dev *tpm_dev; | ||
285 | u8 data; | ||
286 | |||
287 | tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip); | ||
288 | data = TPM_ACCESS_ACTIVE_LOCALITY; | ||
289 | |||
290 | I2C_WRITE_DATA(tpm_dev, TPM_ACCESS, &data, 1); | ||
291 | } | ||
292 | |||
293 | /* | ||
294 | * get_burstcount return the burstcount address 0x19 0x1A | ||
295 | * @param: chip, the chip description | ||
296 | * return: the burstcount. | ||
297 | */ | ||
298 | static int get_burstcount(struct tpm_chip *chip) | ||
299 | { | ||
300 | unsigned long stop; | ||
301 | int burstcnt, status; | ||
302 | u8 tpm_reg, temp; | ||
303 | struct tpm_stm_dev *tpm_dev; | ||
304 | |||
305 | tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip); | ||
306 | |||
307 | stop = jiffies + chip->vendor.timeout_d; | ||
308 | do { | ||
309 | tpm_reg = TPM_STS + 1; | ||
310 | status = I2C_READ_DATA(tpm_dev, tpm_reg, &temp, 1); | ||
311 | if (status < 0) | ||
312 | goto end; | ||
313 | |||
314 | tpm_reg = tpm_reg + 1; | ||
315 | burstcnt = temp; | ||
316 | status = I2C_READ_DATA(tpm_dev, tpm_reg, &temp, 1); | ||
317 | if (status < 0) | ||
318 | goto end; | ||
319 | |||
320 | burstcnt |= temp << 8; | ||
321 | if (burstcnt) | ||
322 | return burstcnt; | ||
323 | msleep(TPM_TIMEOUT); | ||
324 | } while (time_before(jiffies, stop)); | ||
325 | |||
326 | end: | ||
327 | return -EBUSY; | ||
328 | } /* get_burstcount() */ | ||
329 | |||
330 | static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask, | ||
331 | bool check_cancel, bool *canceled) | ||
332 | { | ||
333 | u8 status = chip->ops->status(chip); | ||
334 | |||
335 | *canceled = false; | ||
336 | if ((status & mask) == mask) | ||
337 | return true; | ||
338 | if (check_cancel && chip->ops->req_canceled(chip, status)) { | ||
339 | *canceled = true; | ||
340 | return true; | ||
341 | } | ||
342 | return false; | ||
343 | } | ||
344 | |||
345 | /* | ||
346 | * interrupt_to_status | ||
347 | * @param: irq_mask, the irq mask value to wait | ||
348 | * @return: the corresponding tpm_sts value | ||
349 | */ | ||
350 | static u8 interrupt_to_status(u8 irq_mask) | ||
351 | { | ||
352 | u8 status = 0; | ||
353 | |||
354 | if ((irq_mask & TPM_INTF_STS_VALID_INT) == TPM_INTF_STS_VALID_INT) | ||
355 | status |= TPM_STS_VALID; | ||
356 | if ((irq_mask & TPM_INTF_DATA_AVAIL_INT) == TPM_INTF_DATA_AVAIL_INT) | ||
357 | status |= TPM_STS_DATA_AVAIL; | ||
358 | if ((irq_mask & TPM_INTF_CMD_READY_INT) == TPM_INTF_CMD_READY_INT) | ||
359 | status |= TPM_STS_COMMAND_READY; | ||
360 | |||
361 | return status; | ||
362 | } /* status_to_interrupt() */ | ||
363 | |||
364 | /* | ||
365 | * wait_for_stat wait for a TPM_STS value | ||
366 | * @param: chip, the tpm chip description | ||
367 | * @param: mask, the value mask to wait | ||
368 | * @param: timeout, the timeout | ||
369 | * @param: queue, the wait queue. | ||
370 | * @param: check_cancel, does the command can be cancelled ? | ||
371 | * @return: the tpm status, 0 if success, -ETIME if timeout is reached. | ||
372 | */ | ||
373 | static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, | ||
374 | wait_queue_head_t *queue, bool check_cancel) | ||
375 | { | ||
376 | unsigned long stop; | ||
377 | int ret; | ||
378 | bool canceled = false; | ||
379 | bool condition; | ||
380 | u32 cur_intrs; | ||
381 | u8 interrupt, status; | ||
382 | struct tpm_stm_dev *tpm_dev; | ||
383 | |||
384 | tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip); | ||
385 | |||
386 | /* check current status */ | ||
387 | status = tpm_stm_i2c_status(chip); | ||
388 | if ((status & mask) == mask) | ||
389 | return 0; | ||
390 | |||
391 | stop = jiffies + timeout; | ||
392 | |||
393 | if (chip->vendor.irq) { | ||
394 | cur_intrs = tpm_dev->intrs; | ||
395 | interrupt = clear_interruption(tpm_dev); | ||
396 | enable_irq(chip->vendor.irq); | ||
397 | |||
398 | again: | ||
399 | timeout = stop - jiffies; | ||
400 | if ((long) timeout <= 0) | ||
401 | return -1; | ||
402 | |||
403 | ret = wait_event_interruptible_timeout(*queue, | ||
404 | cur_intrs != tpm_dev->intrs, timeout); | ||
405 | |||
406 | interrupt |= clear_interruption(tpm_dev); | ||
407 | status = interrupt_to_status(interrupt); | ||
408 | condition = wait_for_tpm_stat_cond(chip, mask, | ||
409 | check_cancel, &canceled); | ||
410 | |||
411 | if (ret >= 0 && condition) { | ||
412 | if (canceled) | ||
413 | return -ECANCELED; | ||
414 | return 0; | ||
415 | } | ||
416 | if (ret == -ERESTARTSYS && freezing(current)) { | ||
417 | clear_thread_flag(TIF_SIGPENDING); | ||
418 | goto again; | ||
419 | } | ||
420 | disable_irq_nosync(chip->vendor.irq); | ||
421 | |||
422 | } else { | ||
423 | do { | ||
424 | msleep(TPM_TIMEOUT); | ||
425 | status = chip->ops->status(chip); | ||
426 | if ((status & mask) == mask) | ||
427 | return 0; | ||
428 | } while (time_before(jiffies, stop)); | ||
429 | } | ||
430 | |||
431 | return -ETIME; | ||
432 | } /* wait_for_stat() */ | ||
433 | |||
434 | /* | ||
435 | * recv_data receive data | ||
436 | * @param: chip, the tpm chip description | ||
437 | * @param: buf, the buffer where the data are received | ||
438 | * @param: count, the number of data to receive | ||
439 | * @return: the number of bytes read from TPM FIFO. | ||
440 | */ | ||
441 | static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count) | ||
442 | { | ||
443 | int size = 0, burstcnt, len, ret; | ||
444 | struct tpm_stm_dev *tpm_dev; | ||
445 | |||
446 | tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip); | ||
447 | |||
448 | while (size < count && | ||
449 | wait_for_stat(chip, | ||
450 | TPM_STS_DATA_AVAIL | TPM_STS_VALID, | ||
451 | chip->vendor.timeout_c, | ||
452 | &chip->vendor.read_queue, true) == 0) { | ||
453 | burstcnt = get_burstcount(chip); | ||
454 | if (burstcnt < 0) | ||
455 | return burstcnt; | ||
456 | len = min_t(int, burstcnt, count - size); | ||
457 | ret = I2C_READ_DATA(tpm_dev, TPM_DATA_FIFO, buf + size, len); | ||
458 | if (ret < 0) | ||
459 | return ret; | ||
460 | |||
461 | size += len; | ||
462 | } | ||
463 | return size; | ||
464 | } | ||
465 | |||
466 | /* | ||
467 | * tpm_ioserirq_handler the serirq irq handler | ||
468 | * @param: irq, the tpm chip description | ||
469 | * @param: dev_id, the description of the chip | ||
470 | * @return: the status of the handler. | ||
471 | */ | ||
472 | static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id) | ||
473 | { | ||
474 | struct tpm_chip *chip = dev_id; | ||
475 | struct tpm_stm_dev *tpm_dev; | ||
476 | |||
477 | tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip); | ||
478 | |||
479 | tpm_dev->intrs++; | ||
480 | wake_up_interruptible(&chip->vendor.read_queue); | ||
481 | disable_irq_nosync(chip->vendor.irq); | ||
482 | |||
483 | return IRQ_HANDLED; | ||
484 | } /* tpm_ioserirq_handler() */ | ||
485 | |||
486 | |||
487 | /* | ||
488 | * tpm_stm_i2c_send send TPM commands through the I2C bus. | ||
489 | * | ||
490 | * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h | ||
491 | * @param: buf, the buffer to send. | ||
492 | * @param: count, the number of bytes to send. | ||
493 | * @return: In case of success the number of bytes sent. | ||
494 | * In other case, a < 0 value describing the issue. | ||
495 | */ | ||
496 | static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf, | ||
497 | size_t len) | ||
498 | { | ||
499 | u32 status, i, size; | ||
500 | int burstcnt = 0; | ||
501 | int ret; | ||
502 | u8 data; | ||
503 | struct i2c_client *client; | ||
504 | struct tpm_stm_dev *tpm_dev; | ||
505 | |||
506 | if (!chip) | ||
507 | return -EBUSY; | ||
508 | if (len < TPM_HEADER_SIZE) | ||
509 | return -EBUSY; | ||
510 | |||
511 | tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip); | ||
512 | client = tpm_dev->client; | ||
513 | |||
514 | client->flags = 0; | ||
515 | |||
516 | ret = request_locality(chip); | ||
517 | if (ret < 0) | ||
518 | return ret; | ||
519 | |||
520 | status = tpm_stm_i2c_status(chip); | ||
521 | if ((status & TPM_STS_COMMAND_READY) == 0) { | ||
522 | tpm_stm_i2c_cancel(chip); | ||
523 | if (wait_for_stat | ||
524 | (chip, TPM_STS_COMMAND_READY, chip->vendor.timeout_b, | ||
525 | &chip->vendor.read_queue, false) < 0) { | ||
526 | ret = -ETIME; | ||
527 | goto out_err; | ||
528 | } | ||
529 | } | ||
530 | |||
531 | for (i = 0; i < len - 1;) { | ||
532 | burstcnt = get_burstcount(chip); | ||
533 | if (burstcnt < 0) | ||
534 | return burstcnt; | ||
535 | size = min_t(int, len - i - 1, burstcnt); | ||
536 | ret = I2C_WRITE_DATA(tpm_dev, TPM_DATA_FIFO, buf + i, size); | ||
537 | if (ret < 0) | ||
538 | goto out_err; | ||
539 | |||
540 | i += size; | ||
541 | } | ||
542 | |||
543 | status = tpm_stm_i2c_status(chip); | ||
544 | if ((status & TPM_STS_DATA_EXPECT) == 0) { | ||
545 | ret = -EIO; | ||
546 | goto out_err; | ||
547 | } | ||
548 | |||
549 | ret = I2C_WRITE_DATA(tpm_dev, TPM_DATA_FIFO, buf + len - 1, 1); | ||
550 | if (ret < 0) | ||
551 | goto out_err; | ||
552 | |||
553 | status = tpm_stm_i2c_status(chip); | ||
554 | if ((status & TPM_STS_DATA_EXPECT) != 0) { | ||
555 | ret = -EIO; | ||
556 | goto out_err; | ||
557 | } | ||
558 | |||
559 | data = TPM_STS_GO; | ||
560 | I2C_WRITE_DATA(tpm_dev, TPM_STS, &data, 1); | ||
561 | |||
562 | return len; | ||
563 | out_err: | ||
564 | tpm_stm_i2c_cancel(chip); | ||
565 | release_locality(chip); | ||
566 | return ret; | ||
567 | } | ||
568 | |||
569 | /* | ||
570 | * tpm_stm_i2c_recv received TPM response through the I2C bus. | ||
571 | * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h. | ||
572 | * @param: buf, the buffer to store datas. | ||
573 | * @param: count, the number of bytes to send. | ||
574 | * @return: In case of success the number of bytes received. | ||
575 | * In other case, a < 0 value describing the issue. | ||
576 | */ | ||
577 | static int tpm_stm_i2c_recv(struct tpm_chip *chip, unsigned char *buf, | ||
578 | size_t count) | ||
579 | { | ||
580 | int size = 0; | ||
581 | int expected; | ||
582 | |||
583 | if (!chip) | ||
584 | return -EBUSY; | ||
585 | |||
586 | if (count < TPM_HEADER_SIZE) { | ||
587 | size = -EIO; | ||
588 | goto out; | ||
589 | } | ||
590 | |||
591 | size = recv_data(chip, buf, TPM_HEADER_SIZE); | ||
592 | if (size < TPM_HEADER_SIZE) { | ||
593 | dev_err(chip->pdev, "Unable to read header\n"); | ||
594 | goto out; | ||
595 | } | ||
596 | |||
597 | expected = be32_to_cpu(*(__be32 *)(buf + 2)); | ||
598 | if (expected > count) { | ||
599 | size = -EIO; | ||
600 | goto out; | ||
601 | } | ||
602 | |||
603 | size += recv_data(chip, &buf[TPM_HEADER_SIZE], | ||
604 | expected - TPM_HEADER_SIZE); | ||
605 | if (size < expected) { | ||
606 | dev_err(chip->pdev, "Unable to read remainder of result\n"); | ||
607 | size = -ETIME; | ||
608 | goto out; | ||
609 | } | ||
610 | |||
611 | out: | ||
612 | chip->ops->cancel(chip); | ||
613 | release_locality(chip); | ||
614 | return size; | ||
615 | } | ||
616 | |||
617 | static bool tpm_stm_i2c_req_canceled(struct tpm_chip *chip, u8 status) | ||
618 | { | ||
619 | return (status == TPM_STS_COMMAND_READY); | ||
620 | } | ||
621 | |||
622 | static const struct tpm_class_ops st_i2c_tpm = { | ||
623 | .send = tpm_stm_i2c_send, | ||
624 | .recv = tpm_stm_i2c_recv, | ||
625 | .cancel = tpm_stm_i2c_cancel, | ||
626 | .status = tpm_stm_i2c_status, | ||
627 | .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID, | ||
628 | .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, | ||
629 | .req_canceled = tpm_stm_i2c_req_canceled, | ||
630 | }; | ||
631 | |||
632 | #ifdef CONFIG_OF | ||
633 | static int tpm_stm_i2c_of_request_resources(struct tpm_chip *chip) | ||
634 | { | ||
635 | struct device_node *pp; | ||
636 | struct tpm_stm_dev *tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip); | ||
637 | struct i2c_client *client = tpm_dev->client; | ||
638 | int gpio; | ||
639 | int ret; | ||
640 | |||
641 | pp = client->dev.of_node; | ||
642 | if (!pp) { | ||
643 | dev_err(chip->pdev, "No platform data\n"); | ||
644 | return -ENODEV; | ||
645 | } | ||
646 | |||
647 | /* Get GPIO from device tree */ | ||
648 | gpio = of_get_named_gpio(pp, "lpcpd-gpios", 0); | ||
649 | if (gpio < 0) { | ||
650 | dev_err(chip->pdev, "Failed to retrieve lpcpd-gpios from dts.\n"); | ||
651 | tpm_dev->io_lpcpd = -1; | ||
652 | /* | ||
653 | * lpcpd pin is not specified. This is not an issue as | ||
654 | * power management can be also managed by TPM specific | ||
655 | * commands. So leave with a success status code. | ||
656 | */ | ||
657 | return 0; | ||
658 | } | ||
659 | /* GPIO request and configuration */ | ||
660 | ret = devm_gpio_request_one(&client->dev, gpio, | ||
661 | GPIOF_OUT_INIT_HIGH, "TPM IO LPCPD"); | ||
662 | if (ret) { | ||
663 | dev_err(chip->pdev, "Failed to request lpcpd pin\n"); | ||
664 | return -ENODEV; | ||
665 | } | ||
666 | tpm_dev->io_lpcpd = gpio; | ||
667 | |||
668 | return 0; | ||
669 | } | ||
670 | #else | ||
671 | static int tpm_stm_i2c_of_request_resources(struct tpm_chip *chip) | ||
672 | { | ||
673 | return -ENODEV; | ||
674 | } | ||
675 | #endif | ||
676 | |||
677 | static int tpm_stm_i2c_request_resources(struct i2c_client *client, | ||
678 | struct tpm_chip *chip) | ||
679 | { | ||
680 | struct st33zp24_platform_data *pdata; | ||
681 | struct tpm_stm_dev *tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip); | ||
682 | int ret; | ||
683 | |||
684 | pdata = client->dev.platform_data; | ||
685 | if (!pdata) { | ||
686 | dev_err(chip->pdev, "No platform data\n"); | ||
687 | return -ENODEV; | ||
688 | } | ||
689 | |||
690 | /* store for late use */ | ||
691 | tpm_dev->io_lpcpd = pdata->io_lpcpd; | ||
692 | |||
693 | if (gpio_is_valid(pdata->io_lpcpd)) { | ||
694 | ret = devm_gpio_request_one(&client->dev, | ||
695 | pdata->io_lpcpd, GPIOF_OUT_INIT_HIGH, | ||
696 | "TPM IO_LPCPD"); | ||
697 | if (ret) { | ||
698 | dev_err(chip->pdev, "%s : reset gpio_request failed\n", | ||
699 | __FILE__); | ||
700 | return ret; | ||
701 | } | ||
702 | } | ||
703 | |||
704 | return 0; | ||
705 | } | ||
706 | |||
707 | /* | ||
708 | * tpm_stm_i2c_probe initialize the TPM device | ||
709 | * @param: client, the i2c_client drescription (TPM I2C description). | ||
710 | * @param: id, the i2c_device_id struct. | ||
711 | * @return: 0 in case of success. | ||
712 | * -1 in other case. | ||
713 | */ | ||
714 | static int | ||
715 | tpm_stm_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) | ||
716 | { | ||
717 | int ret; | ||
718 | u8 intmask = 0; | ||
719 | struct tpm_chip *chip; | ||
720 | struct st33zp24_platform_data *platform_data; | ||
721 | struct tpm_stm_dev *tpm_dev; | ||
722 | |||
723 | if (!client) { | ||
724 | pr_info("%s: i2c client is NULL. Device not accessible.\n", | ||
725 | __func__); | ||
726 | return -ENODEV; | ||
727 | } | ||
728 | |||
729 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { | ||
730 | dev_info(&client->dev, "client not i2c capable\n"); | ||
731 | return -ENODEV; | ||
732 | } | ||
733 | |||
734 | tpm_dev = devm_kzalloc(&client->dev, sizeof(struct tpm_stm_dev), | ||
735 | GFP_KERNEL); | ||
736 | if (!tpm_dev) | ||
737 | return -ENOMEM; | ||
738 | |||
739 | chip = tpmm_chip_alloc(&client->dev, &st_i2c_tpm); | ||
740 | if (IS_ERR(chip)) | ||
741 | return PTR_ERR(chip); | ||
742 | |||
743 | TPM_VPRIV(chip) = tpm_dev; | ||
744 | tpm_dev->client = client; | ||
745 | |||
746 | platform_data = client->dev.platform_data; | ||
747 | if (!platform_data && client->dev.of_node) { | ||
748 | ret = tpm_stm_i2c_of_request_resources(chip); | ||
749 | if (ret) | ||
750 | goto _tpm_clean_answer; | ||
751 | } else if (platform_data) { | ||
752 | ret = tpm_stm_i2c_request_resources(client, chip); | ||
753 | if (ret) | ||
754 | goto _tpm_clean_answer; | ||
755 | } | ||
756 | |||
757 | chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT); | ||
758 | chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT); | ||
759 | chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT); | ||
760 | chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT); | ||
761 | |||
762 | chip->vendor.locality = LOCALITY0; | ||
763 | |||
764 | if (client->irq) { | ||
765 | /* INTERRUPT Setup */ | ||
766 | init_waitqueue_head(&chip->vendor.read_queue); | ||
767 | tpm_dev->intrs = 0; | ||
768 | |||
769 | if (request_locality(chip) != LOCALITY0) { | ||
770 | ret = -ENODEV; | ||
771 | goto _tpm_clean_answer; | ||
772 | } | ||
773 | |||
774 | clear_interruption(tpm_dev); | ||
775 | ret = devm_request_irq(&client->dev, client->irq, | ||
776 | tpm_ioserirq_handler, | ||
777 | IRQF_TRIGGER_HIGH, | ||
778 | "TPM SERIRQ management", chip); | ||
779 | if (ret < 0) { | ||
780 | dev_err(chip->pdev, "TPM SERIRQ signals %d not available\n", | ||
781 | client->irq); | ||
782 | goto _tpm_clean_answer; | ||
783 | } | ||
784 | |||
785 | intmask |= TPM_INTF_CMD_READY_INT | ||
786 | | TPM_INTF_STS_VALID_INT | ||
787 | | TPM_INTF_DATA_AVAIL_INT; | ||
788 | |||
789 | ret = I2C_WRITE_DATA(tpm_dev, TPM_INT_ENABLE, &intmask, 1); | ||
790 | if (ret < 0) | ||
791 | goto _tpm_clean_answer; | ||
792 | |||
793 | intmask = TPM_GLOBAL_INT_ENABLE; | ||
794 | ret = I2C_WRITE_DATA(tpm_dev, (TPM_INT_ENABLE + 3), | ||
795 | &intmask, 1); | ||
796 | if (ret < 0) | ||
797 | goto _tpm_clean_answer; | ||
798 | |||
799 | chip->vendor.irq = client->irq; | ||
800 | |||
801 | disable_irq_nosync(chip->vendor.irq); | ||
802 | |||
803 | tpm_gen_interrupt(chip); | ||
804 | } | ||
805 | |||
806 | tpm_get_timeouts(chip); | ||
807 | tpm_do_selftest(chip); | ||
808 | |||
809 | return tpm_chip_register(chip); | ||
810 | _tpm_clean_answer: | ||
811 | dev_info(chip->pdev, "TPM I2C initialisation fail\n"); | ||
812 | return ret; | ||
813 | } | ||
814 | |||
815 | /* | ||
816 | * tpm_stm_i2c_remove remove the TPM device | ||
817 | * @param: client, the i2c_client description (TPM I2C description). | ||
818 | * @return: 0 in case of success. | ||
819 | */ | ||
820 | static int tpm_stm_i2c_remove(struct i2c_client *client) | ||
821 | { | ||
822 | struct tpm_chip *chip = | ||
823 | (struct tpm_chip *) i2c_get_clientdata(client); | ||
824 | |||
825 | if (chip) | ||
826 | tpm_chip_unregister(chip); | ||
827 | |||
828 | return 0; | ||
829 | } | ||
830 | |||
831 | #ifdef CONFIG_PM_SLEEP | ||
832 | /* | ||
833 | * tpm_stm_i2c_pm_suspend suspend the TPM device | ||
834 | * @param: client, the i2c_client drescription (TPM I2C description). | ||
835 | * @param: mesg, the power management message. | ||
836 | * @return: 0 in case of success. | ||
837 | */ | ||
838 | static int tpm_stm_i2c_pm_suspend(struct device *dev) | ||
839 | { | ||
840 | struct st33zp24_platform_data *pin_infos = dev->platform_data; | ||
841 | int ret = 0; | ||
842 | |||
843 | if (gpio_is_valid(pin_infos->io_lpcpd)) | ||
844 | gpio_set_value(pin_infos->io_lpcpd, 0); | ||
845 | else | ||
846 | ret = tpm_pm_suspend(dev); | ||
847 | |||
848 | return ret; | ||
849 | } /* tpm_stm_i2c_suspend() */ | ||
850 | |||
851 | /* | ||
852 | * tpm_stm_i2c_pm_resume resume the TPM device | ||
853 | * @param: client, the i2c_client drescription (TPM I2C description). | ||
854 | * @return: 0 in case of success. | ||
855 | */ | ||
856 | static int tpm_stm_i2c_pm_resume(struct device *dev) | ||
857 | { | ||
858 | struct tpm_chip *chip = dev_get_drvdata(dev); | ||
859 | struct st33zp24_platform_data *pin_infos = dev->platform_data; | ||
860 | |||
861 | int ret = 0; | ||
862 | |||
863 | if (gpio_is_valid(pin_infos->io_lpcpd)) { | ||
864 | gpio_set_value(pin_infos->io_lpcpd, 1); | ||
865 | ret = wait_for_stat(chip, | ||
866 | TPM_STS_VALID, chip->vendor.timeout_b, | ||
867 | &chip->vendor.read_queue, false); | ||
868 | } else { | ||
869 | ret = tpm_pm_resume(dev); | ||
870 | if (!ret) | ||
871 | tpm_do_selftest(chip); | ||
872 | } | ||
873 | return ret; | ||
874 | } /* tpm_stm_i2c_pm_resume() */ | ||
875 | #endif | ||
876 | |||
877 | static const struct i2c_device_id tpm_stm_i2c_id[] = { | ||
878 | {TPM_ST33_I2C, 0}, | ||
879 | {} | ||
880 | }; | ||
881 | MODULE_DEVICE_TABLE(i2c, tpm_stm_i2c_id); | ||
882 | |||
883 | #ifdef CONFIG_OF | ||
884 | static const struct of_device_id of_st33zp24_i2c_match[] = { | ||
885 | { .compatible = "st,st33zp24-i2c", }, | ||
886 | {} | ||
887 | }; | ||
888 | MODULE_DEVICE_TABLE(of, of_st33zp24_i2c_match); | ||
889 | #endif | ||
890 | |||
891 | static SIMPLE_DEV_PM_OPS(tpm_stm_i2c_ops, tpm_stm_i2c_pm_suspend, | ||
892 | tpm_stm_i2c_pm_resume); | ||
893 | |||
894 | static struct i2c_driver tpm_stm_i2c_driver = { | ||
895 | .driver = { | ||
896 | .owner = THIS_MODULE, | ||
897 | .name = TPM_ST33_I2C, | ||
898 | .pm = &tpm_stm_i2c_ops, | ||
899 | .of_match_table = of_match_ptr(of_st33zp24_i2c_match), | ||
900 | }, | ||
901 | .probe = tpm_stm_i2c_probe, | ||
902 | .remove = tpm_stm_i2c_remove, | ||
903 | .id_table = tpm_stm_i2c_id | ||
904 | }; | ||
905 | |||
906 | module_i2c_driver(tpm_stm_i2c_driver); | ||
907 | |||
908 | MODULE_AUTHOR("Christophe Ricard (tpmsupport@st.com)"); | ||
909 | MODULE_DESCRIPTION("STM TPM I2C ST33 Driver"); | ||
910 | MODULE_VERSION("1.2.1"); | ||
911 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c index 29ba520ac24d..6c488e635fdd 100644 --- a/drivers/char/tpm/tpm_infineon.c +++ b/drivers/char/tpm/tpm_infineon.c | |||
@@ -591,27 +591,8 @@ static void tpm_inf_pnp_remove(struct pnp_dev *dev) | |||
591 | } | 591 | } |
592 | } | 592 | } |
593 | 593 | ||
594 | static int tpm_inf_pnp_suspend(struct pnp_dev *dev, pm_message_t pm_state) | 594 | #ifdef CONFIG_PM_SLEEP |
595 | { | 595 | static int tpm_inf_resume(struct device *dev) |
596 | struct tpm_chip *chip = pnp_get_drvdata(dev); | ||
597 | int rc; | ||
598 | if (chip) { | ||
599 | u8 savestate[] = { | ||
600 | 0, 193, /* TPM_TAG_RQU_COMMAND */ | ||
601 | 0, 0, 0, 10, /* blob length (in bytes) */ | ||
602 | 0, 0, 0, 152 /* TPM_ORD_SaveState */ | ||
603 | }; | ||
604 | dev_info(&dev->dev, "saving TPM state\n"); | ||
605 | rc = tpm_inf_send(chip, savestate, sizeof(savestate)); | ||
606 | if (rc < 0) { | ||
607 | dev_err(&dev->dev, "error while saving TPM state\n"); | ||
608 | return rc; | ||
609 | } | ||
610 | } | ||
611 | return 0; | ||
612 | } | ||
613 | |||
614 | static int tpm_inf_pnp_resume(struct pnp_dev *dev) | ||
615 | { | 596 | { |
616 | /* Re-configure TPM after suspending */ | 597 | /* Re-configure TPM after suspending */ |
617 | tpm_config_out(ENABLE_REGISTER_PAIR, TPM_INF_ADDR); | 598 | tpm_config_out(ENABLE_REGISTER_PAIR, TPM_INF_ADDR); |
@@ -625,16 +606,19 @@ static int tpm_inf_pnp_resume(struct pnp_dev *dev) | |||
625 | tpm_config_out(DISABLE_REGISTER_PAIR, TPM_INF_ADDR); | 606 | tpm_config_out(DISABLE_REGISTER_PAIR, TPM_INF_ADDR); |
626 | /* disable RESET, LP and IRQC */ | 607 | /* disable RESET, LP and IRQC */ |
627 | tpm_data_out(RESET_LP_IRQC_DISABLE, CMD); | 608 | tpm_data_out(RESET_LP_IRQC_DISABLE, CMD); |
628 | return tpm_pm_resume(&dev->dev); | 609 | return tpm_pm_resume(dev); |
629 | } | 610 | } |
611 | #endif | ||
612 | static SIMPLE_DEV_PM_OPS(tpm_inf_pm, tpm_pm_suspend, tpm_inf_resume); | ||
630 | 613 | ||
631 | static struct pnp_driver tpm_inf_pnp_driver = { | 614 | static struct pnp_driver tpm_inf_pnp_driver = { |
632 | .name = "tpm_inf_pnp", | 615 | .name = "tpm_inf_pnp", |
633 | .id_table = tpm_inf_pnp_tbl, | 616 | .id_table = tpm_inf_pnp_tbl, |
634 | .probe = tpm_inf_pnp_probe, | 617 | .probe = tpm_inf_pnp_probe, |
635 | .suspend = tpm_inf_pnp_suspend, | 618 | .remove = tpm_inf_pnp_remove, |
636 | .resume = tpm_inf_pnp_resume, | 619 | .driver = { |
637 | .remove = tpm_inf_pnp_remove | 620 | .pm = &tpm_inf_pm, |
621 | } | ||
638 | }; | 622 | }; |
639 | 623 | ||
640 | module_pnp_driver(tpm_inf_pnp_driver); | 624 | module_pnp_driver(tpm_inf_pnp_driver); |
diff --git a/include/linux/platform_data/tpm_stm_st33.h b/include/linux/platform_data/st33zp24.h index ff75310c0f47..817dfdb37885 100644 --- a/include/linux/platform_data/tpm_stm_st33.h +++ b/include/linux/platform_data/st33zp24.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * STMicroelectronics TPM I2C Linux driver for TPM ST33ZP24 | 2 | * STMicroelectronics TPM Linux driver for TPM 1.2 ST33ZP24 |
3 | * Copyright (C) 2009, 2010 STMicroelectronics | 3 | * Copyright (C) 2009 - 2015 STMicroelectronics |
4 | * | 4 | * |
5 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by |
@@ -14,20 +14,9 @@ | |||
14 | * | 14 | * |
15 | * You should have received a copy of the GNU General Public License | 15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | 16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
17 | * | ||
18 | * STMicroelectronics version 1.2.0, Copyright (C) 2010 | ||
19 | * STMicroelectronics comes with ABSOLUTELY NO WARRANTY. | ||
20 | * This is free software, and you are welcome to redistribute it | ||
21 | * under certain conditions. | ||
22 | * | ||
23 | * @Author: Christophe RICARD tpmsupport@st.com | ||
24 | * | ||
25 | * @File: stm_st33_tpm.h | ||
26 | * | ||
27 | * @Date: 09/15/2010 | ||
28 | */ | 17 | */ |
29 | #ifndef __STM_ST33_TPM_H__ | 18 | #ifndef __ST33ZP24_H__ |
30 | #define __STM_ST33_TPM_H__ | 19 | #define __ST33ZP24_H__ |
31 | 20 | ||
32 | #define TPM_ST33_I2C "st33zp24-i2c" | 21 | #define TPM_ST33_I2C "st33zp24-i2c" |
33 | #define TPM_ST33_SPI "st33zp24-spi" | 22 | #define TPM_ST33_SPI "st33zp24-spi" |
@@ -36,4 +25,4 @@ struct st33zp24_platform_data { | |||
36 | int io_lpcpd; | 25 | int io_lpcpd; |
37 | }; | 26 | }; |
38 | 27 | ||
39 | #endif /* __STM_ST33_TPM_H__ */ | 28 | #endif /* __ST33ZP24_H__ */ |
diff --git a/security/lsm_audit.c b/security/lsm_audit.c index 69fdf3bc765b..b526ddc3add5 100644 --- a/security/lsm_audit.c +++ b/security/lsm_audit.c | |||
@@ -211,7 +211,7 @@ static inline void print_ipv4_addr(struct audit_buffer *ab, __be32 addr, | |||
211 | static void dump_common_audit_data(struct audit_buffer *ab, | 211 | static void dump_common_audit_data(struct audit_buffer *ab, |
212 | struct common_audit_data *a) | 212 | struct common_audit_data *a) |
213 | { | 213 | { |
214 | struct task_struct *tsk = current; | 214 | char comm[sizeof(current->comm)]; |
215 | 215 | ||
216 | /* | 216 | /* |
217 | * To keep stack sizes in check force programers to notice if they | 217 | * To keep stack sizes in check force programers to notice if they |
@@ -220,8 +220,8 @@ static void dump_common_audit_data(struct audit_buffer *ab, | |||
220 | */ | 220 | */ |
221 | BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2); | 221 | BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2); |
222 | 222 | ||
223 | audit_log_format(ab, " pid=%d comm=", task_pid_nr(tsk)); | 223 | audit_log_format(ab, " pid=%d comm=", task_pid_nr(current)); |
224 | audit_log_untrustedstring(ab, tsk->comm); | 224 | audit_log_untrustedstring(ab, memcpy(comm, current->comm, sizeof(comm))); |
225 | 225 | ||
226 | switch (a->type) { | 226 | switch (a->type) { |
227 | case LSM_AUDIT_DATA_NONE: | 227 | case LSM_AUDIT_DATA_NONE: |
@@ -276,16 +276,19 @@ static void dump_common_audit_data(struct audit_buffer *ab, | |||
276 | audit_log_format(ab, " ino=%lu", inode->i_ino); | 276 | audit_log_format(ab, " ino=%lu", inode->i_ino); |
277 | break; | 277 | break; |
278 | } | 278 | } |
279 | case LSM_AUDIT_DATA_TASK: | 279 | case LSM_AUDIT_DATA_TASK: { |
280 | tsk = a->u.tsk; | 280 | struct task_struct *tsk = a->u.tsk; |
281 | if (tsk) { | 281 | if (tsk) { |
282 | pid_t pid = task_pid_nr(tsk); | 282 | pid_t pid = task_pid_nr(tsk); |
283 | if (pid) { | 283 | if (pid) { |
284 | char comm[sizeof(tsk->comm)]; | ||
284 | audit_log_format(ab, " pid=%d comm=", pid); | 285 | audit_log_format(ab, " pid=%d comm=", pid); |
285 | audit_log_untrustedstring(ab, tsk->comm); | 286 | audit_log_untrustedstring(ab, |
287 | memcpy(comm, tsk->comm, sizeof(comm))); | ||
286 | } | 288 | } |
287 | } | 289 | } |
288 | break; | 290 | break; |
291 | } | ||
289 | case LSM_AUDIT_DATA_NET: | 292 | case LSM_AUDIT_DATA_NET: |
290 | if (a->u.net->sk) { | 293 | if (a->u.net->sk) { |
291 | struct sock *sk = a->u.net->sk; | 294 | struct sock *sk = a->u.net->sk; |
diff --git a/security/selinux/avc.c b/security/selinux/avc.c index afcc0aed9393..3c17dda9571d 100644 --- a/security/selinux/avc.c +++ b/security/selinux/avc.c | |||
@@ -724,12 +724,10 @@ inline int avc_has_perm_noaudit(u32 ssid, u32 tsid, | |||
724 | rcu_read_lock(); | 724 | rcu_read_lock(); |
725 | 725 | ||
726 | node = avc_lookup(ssid, tsid, tclass); | 726 | node = avc_lookup(ssid, tsid, tclass); |
727 | if (unlikely(!node)) { | 727 | if (unlikely(!node)) |
728 | node = avc_compute_av(ssid, tsid, tclass, avd); | 728 | node = avc_compute_av(ssid, tsid, tclass, avd); |
729 | } else { | 729 | else |
730 | memcpy(avd, &node->ae.avd, sizeof(*avd)); | 730 | memcpy(avd, &node->ae.avd, sizeof(*avd)); |
731 | avd = &node->ae.avd; | ||
732 | } | ||
733 | 731 | ||
734 | denied = requested & ~(avd->allowed); | 732 | denied = requested & ~(avd->allowed); |
735 | if (unlikely(denied)) | 733 | if (unlikely(denied)) |
diff --git a/security/selinux/ss/avtab.c b/security/selinux/ss/avtab.c index a3dd9faa19c0..b64f2772b030 100644 --- a/security/selinux/ss/avtab.c +++ b/security/selinux/ss/avtab.c | |||
@@ -25,10 +25,43 @@ | |||
25 | 25 | ||
26 | static struct kmem_cache *avtab_node_cachep; | 26 | static struct kmem_cache *avtab_node_cachep; |
27 | 27 | ||
28 | static inline int avtab_hash(struct avtab_key *keyp, u16 mask) | 28 | /* Based on MurmurHash3, written by Austin Appleby and placed in the |
29 | * public domain. | ||
30 | */ | ||
31 | static inline int avtab_hash(struct avtab_key *keyp, u32 mask) | ||
29 | { | 32 | { |
30 | return ((keyp->target_class + (keyp->target_type << 2) + | 33 | static const u32 c1 = 0xcc9e2d51; |
31 | (keyp->source_type << 9)) & mask); | 34 | static const u32 c2 = 0x1b873593; |
35 | static const u32 r1 = 15; | ||
36 | static const u32 r2 = 13; | ||
37 | static const u32 m = 5; | ||
38 | static const u32 n = 0xe6546b64; | ||
39 | |||
40 | u32 hash = 0; | ||
41 | |||
42 | #define mix(input) { \ | ||
43 | u32 v = input; \ | ||
44 | v *= c1; \ | ||
45 | v = (v << r1) | (v >> (32 - r1)); \ | ||
46 | v *= c2; \ | ||
47 | hash ^= v; \ | ||
48 | hash = (hash << r2) | (hash >> (32 - r2)); \ | ||
49 | hash = hash * m + n; \ | ||
50 | } | ||
51 | |||
52 | mix(keyp->target_class); | ||
53 | mix(keyp->target_type); | ||
54 | mix(keyp->source_type); | ||
55 | |||
56 | #undef mix | ||
57 | |||
58 | hash ^= hash >> 16; | ||
59 | hash *= 0x85ebca6b; | ||
60 | hash ^= hash >> 13; | ||
61 | hash *= 0xc2b2ae35; | ||
62 | hash ^= hash >> 16; | ||
63 | |||
64 | return hash & mask; | ||
32 | } | 65 | } |
33 | 66 | ||
34 | static struct avtab_node* | 67 | static struct avtab_node* |
@@ -46,8 +79,12 @@ avtab_insert_node(struct avtab *h, int hvalue, | |||
46 | newnode->next = prev->next; | 79 | newnode->next = prev->next; |
47 | prev->next = newnode; | 80 | prev->next = newnode; |
48 | } else { | 81 | } else { |
49 | newnode->next = h->htable[hvalue]; | 82 | newnode->next = flex_array_get_ptr(h->htable, hvalue); |
50 | h->htable[hvalue] = newnode; | 83 | if (flex_array_put_ptr(h->htable, hvalue, newnode, |
84 | GFP_KERNEL|__GFP_ZERO)) { | ||
85 | kmem_cache_free(avtab_node_cachep, newnode); | ||
86 | return NULL; | ||
87 | } | ||
51 | } | 88 | } |
52 | 89 | ||
53 | h->nel++; | 90 | h->nel++; |
@@ -64,7 +101,7 @@ static int avtab_insert(struct avtab *h, struct avtab_key *key, struct avtab_dat | |||
64 | return -EINVAL; | 101 | return -EINVAL; |
65 | 102 | ||
66 | hvalue = avtab_hash(key, h->mask); | 103 | hvalue = avtab_hash(key, h->mask); |
67 | for (prev = NULL, cur = h->htable[hvalue]; | 104 | for (prev = NULL, cur = flex_array_get_ptr(h->htable, hvalue); |
68 | cur; | 105 | cur; |
69 | prev = cur, cur = cur->next) { | 106 | prev = cur, cur = cur->next) { |
70 | if (key->source_type == cur->key.source_type && | 107 | if (key->source_type == cur->key.source_type && |
@@ -104,7 +141,7 @@ avtab_insert_nonunique(struct avtab *h, struct avtab_key *key, struct avtab_datu | |||
104 | if (!h || !h->htable) | 141 | if (!h || !h->htable) |
105 | return NULL; | 142 | return NULL; |
106 | hvalue = avtab_hash(key, h->mask); | 143 | hvalue = avtab_hash(key, h->mask); |
107 | for (prev = NULL, cur = h->htable[hvalue]; | 144 | for (prev = NULL, cur = flex_array_get_ptr(h->htable, hvalue); |
108 | cur; | 145 | cur; |
109 | prev = cur, cur = cur->next) { | 146 | prev = cur, cur = cur->next) { |
110 | if (key->source_type == cur->key.source_type && | 147 | if (key->source_type == cur->key.source_type && |
@@ -135,7 +172,8 @@ struct avtab_datum *avtab_search(struct avtab *h, struct avtab_key *key) | |||
135 | return NULL; | 172 | return NULL; |
136 | 173 | ||
137 | hvalue = avtab_hash(key, h->mask); | 174 | hvalue = avtab_hash(key, h->mask); |
138 | for (cur = h->htable[hvalue]; cur; cur = cur->next) { | 175 | for (cur = flex_array_get_ptr(h->htable, hvalue); cur; |
176 | cur = cur->next) { | ||
139 | if (key->source_type == cur->key.source_type && | 177 | if (key->source_type == cur->key.source_type && |
140 | key->target_type == cur->key.target_type && | 178 | key->target_type == cur->key.target_type && |
141 | key->target_class == cur->key.target_class && | 179 | key->target_class == cur->key.target_class && |
@@ -170,7 +208,8 @@ avtab_search_node(struct avtab *h, struct avtab_key *key) | |||
170 | return NULL; | 208 | return NULL; |
171 | 209 | ||
172 | hvalue = avtab_hash(key, h->mask); | 210 | hvalue = avtab_hash(key, h->mask); |
173 | for (cur = h->htable[hvalue]; cur; cur = cur->next) { | 211 | for (cur = flex_array_get_ptr(h->htable, hvalue); cur; |
212 | cur = cur->next) { | ||
174 | if (key->source_type == cur->key.source_type && | 213 | if (key->source_type == cur->key.source_type && |
175 | key->target_type == cur->key.target_type && | 214 | key->target_type == cur->key.target_type && |
176 | key->target_class == cur->key.target_class && | 215 | key->target_class == cur->key.target_class && |
@@ -228,15 +267,14 @@ void avtab_destroy(struct avtab *h) | |||
228 | return; | 267 | return; |
229 | 268 | ||
230 | for (i = 0; i < h->nslot; i++) { | 269 | for (i = 0; i < h->nslot; i++) { |
231 | cur = h->htable[i]; | 270 | cur = flex_array_get_ptr(h->htable, i); |
232 | while (cur) { | 271 | while (cur) { |
233 | temp = cur; | 272 | temp = cur; |
234 | cur = cur->next; | 273 | cur = cur->next; |
235 | kmem_cache_free(avtab_node_cachep, temp); | 274 | kmem_cache_free(avtab_node_cachep, temp); |
236 | } | 275 | } |
237 | h->htable[i] = NULL; | ||
238 | } | 276 | } |
239 | kfree(h->htable); | 277 | flex_array_free(h->htable); |
240 | h->htable = NULL; | 278 | h->htable = NULL; |
241 | h->nslot = 0; | 279 | h->nslot = 0; |
242 | h->mask = 0; | 280 | h->mask = 0; |
@@ -251,7 +289,7 @@ int avtab_init(struct avtab *h) | |||
251 | 289 | ||
252 | int avtab_alloc(struct avtab *h, u32 nrules) | 290 | int avtab_alloc(struct avtab *h, u32 nrules) |
253 | { | 291 | { |
254 | u16 mask = 0; | 292 | u32 mask = 0; |
255 | u32 shift = 0; | 293 | u32 shift = 0; |
256 | u32 work = nrules; | 294 | u32 work = nrules; |
257 | u32 nslot = 0; | 295 | u32 nslot = 0; |
@@ -270,7 +308,8 @@ int avtab_alloc(struct avtab *h, u32 nrules) | |||
270 | nslot = MAX_AVTAB_HASH_BUCKETS; | 308 | nslot = MAX_AVTAB_HASH_BUCKETS; |
271 | mask = nslot - 1; | 309 | mask = nslot - 1; |
272 | 310 | ||
273 | h->htable = kcalloc(nslot, sizeof(*(h->htable)), GFP_KERNEL); | 311 | h->htable = flex_array_alloc(sizeof(struct avtab_node *), nslot, |
312 | GFP_KERNEL | __GFP_ZERO); | ||
274 | if (!h->htable) | 313 | if (!h->htable) |
275 | return -ENOMEM; | 314 | return -ENOMEM; |
276 | 315 | ||
@@ -293,7 +332,7 @@ void avtab_hash_eval(struct avtab *h, char *tag) | |||
293 | max_chain_len = 0; | 332 | max_chain_len = 0; |
294 | chain2_len_sum = 0; | 333 | chain2_len_sum = 0; |
295 | for (i = 0; i < h->nslot; i++) { | 334 | for (i = 0; i < h->nslot; i++) { |
296 | cur = h->htable[i]; | 335 | cur = flex_array_get_ptr(h->htable, i); |
297 | if (cur) { | 336 | if (cur) { |
298 | slots_used++; | 337 | slots_used++; |
299 | chain_len = 0; | 338 | chain_len = 0; |
@@ -534,7 +573,8 @@ int avtab_write(struct policydb *p, struct avtab *a, void *fp) | |||
534 | return rc; | 573 | return rc; |
535 | 574 | ||
536 | for (i = 0; i < a->nslot; i++) { | 575 | for (i = 0; i < a->nslot; i++) { |
537 | for (cur = a->htable[i]; cur; cur = cur->next) { | 576 | for (cur = flex_array_get_ptr(a->htable, i); cur; |
577 | cur = cur->next) { | ||
538 | rc = avtab_write_item(p, cur, fp); | 578 | rc = avtab_write_item(p, cur, fp); |
539 | if (rc) | 579 | if (rc) |
540 | return rc; | 580 | return rc; |
diff --git a/security/selinux/ss/avtab.h b/security/selinux/ss/avtab.h index 63ce2f9e441d..adb451cd44f9 100644 --- a/security/selinux/ss/avtab.h +++ b/security/selinux/ss/avtab.h | |||
@@ -23,6 +23,8 @@ | |||
23 | #ifndef _SS_AVTAB_H_ | 23 | #ifndef _SS_AVTAB_H_ |
24 | #define _SS_AVTAB_H_ | 24 | #define _SS_AVTAB_H_ |
25 | 25 | ||
26 | #include <linux/flex_array.h> | ||
27 | |||
26 | struct avtab_key { | 28 | struct avtab_key { |
27 | u16 source_type; /* source type */ | 29 | u16 source_type; /* source type */ |
28 | u16 target_type; /* target type */ | 30 | u16 target_type; /* target type */ |
@@ -51,10 +53,10 @@ struct avtab_node { | |||
51 | }; | 53 | }; |
52 | 54 | ||
53 | struct avtab { | 55 | struct avtab { |
54 | struct avtab_node **htable; | 56 | struct flex_array *htable; |
55 | u32 nel; /* number of elements */ | 57 | u32 nel; /* number of elements */ |
56 | u32 nslot; /* number of hash slots */ | 58 | u32 nslot; /* number of hash slots */ |
57 | u16 mask; /* mask to compute hash func */ | 59 | u32 mask; /* mask to compute hash func */ |
58 | 60 | ||
59 | }; | 61 | }; |
60 | 62 | ||
@@ -84,7 +86,7 @@ struct avtab_node *avtab_search_node_next(struct avtab_node *node, int specified | |||
84 | void avtab_cache_init(void); | 86 | void avtab_cache_init(void); |
85 | void avtab_cache_destroy(void); | 87 | void avtab_cache_destroy(void); |
86 | 88 | ||
87 | #define MAX_AVTAB_HASH_BITS 11 | 89 | #define MAX_AVTAB_HASH_BITS 16 |
88 | #define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS) | 90 | #define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS) |
89 | 91 | ||
90 | #endif /* _SS_AVTAB_H_ */ | 92 | #endif /* _SS_AVTAB_H_ */ |
diff --git a/security/selinux/ss/mls.c b/security/selinux/ss/mls.c index d307b37ddc2b..e1088842232c 100644 --- a/security/selinux/ss/mls.c +++ b/security/selinux/ss/mls.c | |||
@@ -654,19 +654,15 @@ int mls_import_netlbl_cat(struct context *context, | |||
654 | 654 | ||
655 | rc = ebitmap_netlbl_import(&context->range.level[0].cat, | 655 | rc = ebitmap_netlbl_import(&context->range.level[0].cat, |
656 | secattr->attr.mls.cat); | 656 | secattr->attr.mls.cat); |
657 | if (rc != 0) | 657 | if (rc) |
658 | goto import_netlbl_cat_failure; | ||
659 | |||
660 | rc = ebitmap_cpy(&context->range.level[1].cat, | ||
661 | &context->range.level[0].cat); | ||
662 | if (rc != 0) | ||
663 | goto import_netlbl_cat_failure; | 658 | goto import_netlbl_cat_failure; |
659 | memcpy(&context->range.level[1].cat, &context->range.level[0].cat, | ||
660 | sizeof(context->range.level[0].cat)); | ||
664 | 661 | ||
665 | return 0; | 662 | return 0; |
666 | 663 | ||
667 | import_netlbl_cat_failure: | 664 | import_netlbl_cat_failure: |
668 | ebitmap_destroy(&context->range.level[0].cat); | 665 | ebitmap_destroy(&context->range.level[0].cat); |
669 | ebitmap_destroy(&context->range.level[1].cat); | ||
670 | return rc; | 666 | return rc; |
671 | } | 667 | } |
672 | #endif /* CONFIG_NETLABEL */ | 668 | #endif /* CONFIG_NETLABEL */ |
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index a1d3944751b9..9e2d82070915 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c | |||
@@ -3179,13 +3179,9 @@ int security_netlbl_secattr_to_sid(struct netlbl_lsm_secattr *secattr, | |||
3179 | ctx_new.type = ctx->type; | 3179 | ctx_new.type = ctx->type; |
3180 | mls_import_netlbl_lvl(&ctx_new, secattr); | 3180 | mls_import_netlbl_lvl(&ctx_new, secattr); |
3181 | if (secattr->flags & NETLBL_SECATTR_MLS_CAT) { | 3181 | if (secattr->flags & NETLBL_SECATTR_MLS_CAT) { |
3182 | rc = ebitmap_netlbl_import(&ctx_new.range.level[0].cat, | 3182 | rc = mls_import_netlbl_cat(&ctx_new, secattr); |
3183 | secattr->attr.mls.cat); | ||
3184 | if (rc) | 3183 | if (rc) |
3185 | goto out; | 3184 | goto out; |
3186 | memcpy(&ctx_new.range.level[1].cat, | ||
3187 | &ctx_new.range.level[0].cat, | ||
3188 | sizeof(ctx_new.range.level[0].cat)); | ||
3189 | } | 3185 | } |
3190 | rc = -EIDRM; | 3186 | rc = -EIDRM; |
3191 | if (!mls_context_isvalid(&policydb, &ctx_new)) | 3187 | if (!mls_context_isvalid(&policydb, &ctx_new)) |
diff --git a/security/smack/smack.h b/security/smack/smack.h index 67ccb7b2b89b..49eada6266ec 100644 --- a/security/smack/smack.h +++ b/security/smack/smack.h | |||
@@ -105,6 +105,7 @@ struct task_smack { | |||
105 | #define SMK_INODE_INSTANT 0x01 /* inode is instantiated */ | 105 | #define SMK_INODE_INSTANT 0x01 /* inode is instantiated */ |
106 | #define SMK_INODE_TRANSMUTE 0x02 /* directory is transmuting */ | 106 | #define SMK_INODE_TRANSMUTE 0x02 /* directory is transmuting */ |
107 | #define SMK_INODE_CHANGED 0x04 /* smack was transmuted */ | 107 | #define SMK_INODE_CHANGED 0x04 /* smack was transmuted */ |
108 | #define SMK_INODE_IMPURE 0x08 /* involved in an impure transaction */ | ||
108 | 109 | ||
109 | /* | 110 | /* |
110 | * A label access rule. | 111 | * A label access rule. |
@@ -193,6 +194,10 @@ struct smk_port_label { | |||
193 | #define MAY_LOCK 0x00002000 /* Locks should be writes, but ... */ | 194 | #define MAY_LOCK 0x00002000 /* Locks should be writes, but ... */ |
194 | #define MAY_BRINGUP 0x00004000 /* Report use of this rule */ | 195 | #define MAY_BRINGUP 0x00004000 /* Report use of this rule */ |
195 | 196 | ||
197 | #define SMACK_BRINGUP_ALLOW 1 /* Allow bringup mode */ | ||
198 | #define SMACK_UNCONFINED_SUBJECT 2 /* Allow unconfined label */ | ||
199 | #define SMACK_UNCONFINED_OBJECT 3 /* Allow unconfined label */ | ||
200 | |||
196 | /* | 201 | /* |
197 | * Just to make the common cases easier to deal with | 202 | * Just to make the common cases easier to deal with |
198 | */ | 203 | */ |
@@ -254,6 +259,9 @@ extern int smack_cipso_mapped; | |||
254 | extern struct smack_known *smack_net_ambient; | 259 | extern struct smack_known *smack_net_ambient; |
255 | extern struct smack_known *smack_onlycap; | 260 | extern struct smack_known *smack_onlycap; |
256 | extern struct smack_known *smack_syslog_label; | 261 | extern struct smack_known *smack_syslog_label; |
262 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | ||
263 | extern struct smack_known *smack_unconfined; | ||
264 | #endif | ||
257 | extern struct smack_known smack_cipso_option; | 265 | extern struct smack_known smack_cipso_option; |
258 | extern int smack_ptrace_rule; | 266 | extern int smack_ptrace_rule; |
259 | 267 | ||
diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c index 1158430f5bb9..0f410fc56e33 100644 --- a/security/smack/smack_access.c +++ b/security/smack/smack_access.c | |||
@@ -130,7 +130,8 @@ int smk_access(struct smack_known *subject, struct smack_known *object, | |||
130 | 130 | ||
131 | /* | 131 | /* |
132 | * Hardcoded comparisons. | 132 | * Hardcoded comparisons. |
133 | * | 133 | */ |
134 | /* | ||
134 | * A star subject can't access any object. | 135 | * A star subject can't access any object. |
135 | */ | 136 | */ |
136 | if (subject == &smack_known_star) { | 137 | if (subject == &smack_known_star) { |
@@ -189,10 +190,20 @@ int smk_access(struct smack_known *subject, struct smack_known *object, | |||
189 | * succeed because of "b" rules. | 190 | * succeed because of "b" rules. |
190 | */ | 191 | */ |
191 | if (may & MAY_BRINGUP) | 192 | if (may & MAY_BRINGUP) |
192 | rc = MAY_BRINGUP; | 193 | rc = SMACK_BRINGUP_ALLOW; |
193 | #endif | 194 | #endif |
194 | 195 | ||
195 | out_audit: | 196 | out_audit: |
197 | |||
198 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | ||
199 | if (rc < 0) { | ||
200 | if (object == smack_unconfined) | ||
201 | rc = SMACK_UNCONFINED_OBJECT; | ||
202 | if (subject == smack_unconfined) | ||
203 | rc = SMACK_UNCONFINED_SUBJECT; | ||
204 | } | ||
205 | #endif | ||
206 | |||
196 | #ifdef CONFIG_AUDIT | 207 | #ifdef CONFIG_AUDIT |
197 | if (a) | 208 | if (a) |
198 | smack_log(subject->smk_known, object->smk_known, | 209 | smack_log(subject->smk_known, object->smk_known, |
@@ -338,19 +349,16 @@ static void smack_log_callback(struct audit_buffer *ab, void *a) | |||
338 | void smack_log(char *subject_label, char *object_label, int request, | 349 | void smack_log(char *subject_label, char *object_label, int request, |
339 | int result, struct smk_audit_info *ad) | 350 | int result, struct smk_audit_info *ad) |
340 | { | 351 | { |
352 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | ||
353 | char request_buffer[SMK_NUM_ACCESS_TYPE + 5]; | ||
354 | #else | ||
341 | char request_buffer[SMK_NUM_ACCESS_TYPE + 1]; | 355 | char request_buffer[SMK_NUM_ACCESS_TYPE + 1]; |
356 | #endif | ||
342 | struct smack_audit_data *sad; | 357 | struct smack_audit_data *sad; |
343 | struct common_audit_data *a = &ad->a; | 358 | struct common_audit_data *a = &ad->a; |
344 | 359 | ||
345 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | ||
346 | /* | ||
347 | * The result may be positive in bringup mode. | ||
348 | */ | ||
349 | if (result > 0) | ||
350 | result = 0; | ||
351 | #endif | ||
352 | /* check if we have to log the current event */ | 360 | /* check if we have to log the current event */ |
353 | if (result != 0 && (log_policy & SMACK_AUDIT_DENIED) == 0) | 361 | if (result < 0 && (log_policy & SMACK_AUDIT_DENIED) == 0) |
354 | return; | 362 | return; |
355 | if (result == 0 && (log_policy & SMACK_AUDIT_ACCEPT) == 0) | 363 | if (result == 0 && (log_policy & SMACK_AUDIT_ACCEPT) == 0) |
356 | return; | 364 | return; |
@@ -364,6 +372,21 @@ void smack_log(char *subject_label, char *object_label, int request, | |||
364 | smack_str_from_perm(request_buffer, request); | 372 | smack_str_from_perm(request_buffer, request); |
365 | sad->subject = subject_label; | 373 | sad->subject = subject_label; |
366 | sad->object = object_label; | 374 | sad->object = object_label; |
375 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | ||
376 | /* | ||
377 | * The result may be positive in bringup mode. | ||
378 | * A positive result is an allow, but not for normal reasons. | ||
379 | * Mark it as successful, but don't filter it out even if | ||
380 | * the logging policy says to do so. | ||
381 | */ | ||
382 | if (result == SMACK_UNCONFINED_SUBJECT) | ||
383 | strcat(request_buffer, "(US)"); | ||
384 | else if (result == SMACK_UNCONFINED_OBJECT) | ||
385 | strcat(request_buffer, "(UO)"); | ||
386 | |||
387 | if (result > 0) | ||
388 | result = 0; | ||
389 | #endif | ||
367 | sad->request = request_buffer; | 390 | sad->request = request_buffer; |
368 | sad->result = result; | 391 | sad->result = result; |
369 | 392 | ||
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 1511965549b8..69fdc384af30 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c | |||
@@ -57,6 +57,13 @@ static struct kmem_cache *smack_inode_cache; | |||
57 | int smack_enabled; | 57 | int smack_enabled; |
58 | 58 | ||
59 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | 59 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP |
60 | static char *smk_bu_mess[] = { | ||
61 | "Bringup Error", /* Unused */ | ||
62 | "Bringup", /* SMACK_BRINGUP_ALLOW */ | ||
63 | "Unconfined Subject", /* SMACK_UNCONFINED_SUBJECT */ | ||
64 | "Unconfined Object", /* SMACK_UNCONFINED_OBJECT */ | ||
65 | }; | ||
66 | |||
60 | static void smk_bu_mode(int mode, char *s) | 67 | static void smk_bu_mode(int mode, char *s) |
61 | { | 68 | { |
62 | int i = 0; | 69 | int i = 0; |
@@ -87,9 +94,11 @@ static int smk_bu_note(char *note, struct smack_known *sskp, | |||
87 | 94 | ||
88 | if (rc <= 0) | 95 | if (rc <= 0) |
89 | return rc; | 96 | return rc; |
97 | if (rc > SMACK_UNCONFINED_OBJECT) | ||
98 | rc = 0; | ||
90 | 99 | ||
91 | smk_bu_mode(mode, acc); | 100 | smk_bu_mode(mode, acc); |
92 | pr_info("Smack Bringup: (%s %s %s) %s\n", | 101 | pr_info("Smack %s: (%s %s %s) %s\n", smk_bu_mess[rc], |
93 | sskp->smk_known, oskp->smk_known, acc, note); | 102 | sskp->smk_known, oskp->smk_known, acc, note); |
94 | return 0; | 103 | return 0; |
95 | } | 104 | } |
@@ -106,9 +115,11 @@ static int smk_bu_current(char *note, struct smack_known *oskp, | |||
106 | 115 | ||
107 | if (rc <= 0) | 116 | if (rc <= 0) |
108 | return rc; | 117 | return rc; |
118 | if (rc > SMACK_UNCONFINED_OBJECT) | ||
119 | rc = 0; | ||
109 | 120 | ||
110 | smk_bu_mode(mode, acc); | 121 | smk_bu_mode(mode, acc); |
111 | pr_info("Smack Bringup: (%s %s %s) %s %s\n", | 122 | pr_info("Smack %s: (%s %s %s) %s %s\n", smk_bu_mess[rc], |
112 | tsp->smk_task->smk_known, oskp->smk_known, | 123 | tsp->smk_task->smk_known, oskp->smk_known, |
113 | acc, current->comm, note); | 124 | acc, current->comm, note); |
114 | return 0; | 125 | return 0; |
@@ -126,9 +137,11 @@ static int smk_bu_task(struct task_struct *otp, int mode, int rc) | |||
126 | 137 | ||
127 | if (rc <= 0) | 138 | if (rc <= 0) |
128 | return rc; | 139 | return rc; |
140 | if (rc > SMACK_UNCONFINED_OBJECT) | ||
141 | rc = 0; | ||
129 | 142 | ||
130 | smk_bu_mode(mode, acc); | 143 | smk_bu_mode(mode, acc); |
131 | pr_info("Smack Bringup: (%s %s %s) %s to %s\n", | 144 | pr_info("Smack %s: (%s %s %s) %s to %s\n", smk_bu_mess[rc], |
132 | tsp->smk_task->smk_known, smk_task->smk_known, acc, | 145 | tsp->smk_task->smk_known, smk_task->smk_known, acc, |
133 | current->comm, otp->comm); | 146 | current->comm, otp->comm); |
134 | return 0; | 147 | return 0; |
@@ -141,14 +154,25 @@ static int smk_bu_task(struct task_struct *otp, int mode, int rc) | |||
141 | static int smk_bu_inode(struct inode *inode, int mode, int rc) | 154 | static int smk_bu_inode(struct inode *inode, int mode, int rc) |
142 | { | 155 | { |
143 | struct task_smack *tsp = current_security(); | 156 | struct task_smack *tsp = current_security(); |
157 | struct inode_smack *isp = inode->i_security; | ||
144 | char acc[SMK_NUM_ACCESS_TYPE + 1]; | 158 | char acc[SMK_NUM_ACCESS_TYPE + 1]; |
145 | 159 | ||
160 | if (isp->smk_flags & SMK_INODE_IMPURE) | ||
161 | pr_info("Smack Unconfined Corruption: inode=(%s %ld) %s\n", | ||
162 | inode->i_sb->s_id, inode->i_ino, current->comm); | ||
163 | |||
146 | if (rc <= 0) | 164 | if (rc <= 0) |
147 | return rc; | 165 | return rc; |
166 | if (rc > SMACK_UNCONFINED_OBJECT) | ||
167 | rc = 0; | ||
168 | if (rc == SMACK_UNCONFINED_SUBJECT && | ||
169 | (mode & (MAY_WRITE | MAY_APPEND))) | ||
170 | isp->smk_flags |= SMK_INODE_IMPURE; | ||
148 | 171 | ||
149 | smk_bu_mode(mode, acc); | 172 | smk_bu_mode(mode, acc); |
150 | pr_info("Smack Bringup: (%s %s %s) inode=(%s %ld) %s\n", | 173 | |
151 | tsp->smk_task->smk_known, smk_of_inode(inode)->smk_known, acc, | 174 | pr_info("Smack %s: (%s %s %s) inode=(%s %ld) %s\n", smk_bu_mess[rc], |
175 | tsp->smk_task->smk_known, isp->smk_inode->smk_known, acc, | ||
152 | inode->i_sb->s_id, inode->i_ino, current->comm); | 176 | inode->i_sb->s_id, inode->i_ino, current->comm); |
153 | return 0; | 177 | return 0; |
154 | } | 178 | } |
@@ -162,13 +186,20 @@ static int smk_bu_file(struct file *file, int mode, int rc) | |||
162 | struct task_smack *tsp = current_security(); | 186 | struct task_smack *tsp = current_security(); |
163 | struct smack_known *sskp = tsp->smk_task; | 187 | struct smack_known *sskp = tsp->smk_task; |
164 | struct inode *inode = file_inode(file); | 188 | struct inode *inode = file_inode(file); |
189 | struct inode_smack *isp = inode->i_security; | ||
165 | char acc[SMK_NUM_ACCESS_TYPE + 1]; | 190 | char acc[SMK_NUM_ACCESS_TYPE + 1]; |
166 | 191 | ||
192 | if (isp->smk_flags & SMK_INODE_IMPURE) | ||
193 | pr_info("Smack Unconfined Corruption: inode=(%s %ld) %s\n", | ||
194 | inode->i_sb->s_id, inode->i_ino, current->comm); | ||
195 | |||
167 | if (rc <= 0) | 196 | if (rc <= 0) |
168 | return rc; | 197 | return rc; |
198 | if (rc > SMACK_UNCONFINED_OBJECT) | ||
199 | rc = 0; | ||
169 | 200 | ||
170 | smk_bu_mode(mode, acc); | 201 | smk_bu_mode(mode, acc); |
171 | pr_info("Smack Bringup: (%s %s %s) file=(%s %ld %pD) %s\n", | 202 | pr_info("Smack %s: (%s %s %s) file=(%s %ld %pD) %s\n", smk_bu_mess[rc], |
172 | sskp->smk_known, smk_of_inode(inode)->smk_known, acc, | 203 | sskp->smk_known, smk_of_inode(inode)->smk_known, acc, |
173 | inode->i_sb->s_id, inode->i_ino, file, | 204 | inode->i_sb->s_id, inode->i_ino, file, |
174 | current->comm); | 205 | current->comm); |
@@ -185,13 +216,20 @@ static int smk_bu_credfile(const struct cred *cred, struct file *file, | |||
185 | struct task_smack *tsp = cred->security; | 216 | struct task_smack *tsp = cred->security; |
186 | struct smack_known *sskp = tsp->smk_task; | 217 | struct smack_known *sskp = tsp->smk_task; |
187 | struct inode *inode = file->f_inode; | 218 | struct inode *inode = file->f_inode; |
219 | struct inode_smack *isp = inode->i_security; | ||
188 | char acc[SMK_NUM_ACCESS_TYPE + 1]; | 220 | char acc[SMK_NUM_ACCESS_TYPE + 1]; |
189 | 221 | ||
222 | if (isp->smk_flags & SMK_INODE_IMPURE) | ||
223 | pr_info("Smack Unconfined Corruption: inode=(%s %ld) %s\n", | ||
224 | inode->i_sb->s_id, inode->i_ino, current->comm); | ||
225 | |||
190 | if (rc <= 0) | 226 | if (rc <= 0) |
191 | return rc; | 227 | return rc; |
228 | if (rc > SMACK_UNCONFINED_OBJECT) | ||
229 | rc = 0; | ||
192 | 230 | ||
193 | smk_bu_mode(mode, acc); | 231 | smk_bu_mode(mode, acc); |
194 | pr_info("Smack Bringup: (%s %s %s) file=(%s %ld %pD) %s\n", | 232 | pr_info("Smack %s: (%s %s %s) file=(%s %ld %pD) %s\n", smk_bu_mess[rc], |
195 | sskp->smk_known, smk_of_inode(inode)->smk_known, acc, | 233 | sskp->smk_known, smk_of_inode(inode)->smk_known, acc, |
196 | inode->i_sb->s_id, inode->i_ino, file, | 234 | inode->i_sb->s_id, inode->i_ino, file, |
197 | current->comm); | 235 | current->comm); |
@@ -2449,7 +2487,21 @@ static int smack_inode_setsecurity(struct inode *inode, const char *name, | |||
2449 | static int smack_socket_post_create(struct socket *sock, int family, | 2487 | static int smack_socket_post_create(struct socket *sock, int family, |
2450 | int type, int protocol, int kern) | 2488 | int type, int protocol, int kern) |
2451 | { | 2489 | { |
2452 | if (family != PF_INET || sock->sk == NULL) | 2490 | struct socket_smack *ssp; |
2491 | |||
2492 | if (sock->sk == NULL) | ||
2493 | return 0; | ||
2494 | |||
2495 | /* | ||
2496 | * Sockets created by kernel threads receive web label. | ||
2497 | */ | ||
2498 | if (unlikely(current->flags & PF_KTHREAD)) { | ||
2499 | ssp = sock->sk->sk_security; | ||
2500 | ssp->smk_in = &smack_known_web; | ||
2501 | ssp->smk_out = &smack_known_web; | ||
2502 | } | ||
2503 | |||
2504 | if (family != PF_INET) | ||
2453 | return 0; | 2505 | return 0; |
2454 | /* | 2506 | /* |
2455 | * Set the outbound netlbl. | 2507 | * Set the outbound netlbl. |
@@ -3983,6 +4035,36 @@ static int smack_key_permission(key_ref_t key_ref, | |||
3983 | rc = smk_bu_note("key access", tkp, keyp->security, request, rc); | 4035 | rc = smk_bu_note("key access", tkp, keyp->security, request, rc); |
3984 | return rc; | 4036 | return rc; |
3985 | } | 4037 | } |
4038 | |||
4039 | /* | ||
4040 | * smack_key_getsecurity - Smack label tagging the key | ||
4041 | * @key points to the key to be queried | ||
4042 | * @_buffer points to a pointer that should be set to point to the | ||
4043 | * resulting string (if no label or an error occurs). | ||
4044 | * Return the length of the string (including terminating NUL) or -ve if | ||
4045 | * an error. | ||
4046 | * May also return 0 (and a NULL buffer pointer) if there is no label. | ||
4047 | */ | ||
4048 | static int smack_key_getsecurity(struct key *key, char **_buffer) | ||
4049 | { | ||
4050 | struct smack_known *skp = key->security; | ||
4051 | size_t length; | ||
4052 | char *copy; | ||
4053 | |||
4054 | if (key->security == NULL) { | ||
4055 | *_buffer = NULL; | ||
4056 | return 0; | ||
4057 | } | ||
4058 | |||
4059 | copy = kstrdup(skp->smk_known, GFP_KERNEL); | ||
4060 | if (copy == NULL) | ||
4061 | return -ENOMEM; | ||
4062 | length = strlen(copy) + 1; | ||
4063 | |||
4064 | *_buffer = copy; | ||
4065 | return length; | ||
4066 | } | ||
4067 | |||
3986 | #endif /* CONFIG_KEYS */ | 4068 | #endif /* CONFIG_KEYS */ |
3987 | 4069 | ||
3988 | /* | 4070 | /* |
@@ -4307,6 +4389,7 @@ struct security_operations smack_ops = { | |||
4307 | .key_alloc = smack_key_alloc, | 4389 | .key_alloc = smack_key_alloc, |
4308 | .key_free = smack_key_free, | 4390 | .key_free = smack_key_free, |
4309 | .key_permission = smack_key_permission, | 4391 | .key_permission = smack_key_permission, |
4392 | .key_getsecurity = smack_key_getsecurity, | ||
4310 | #endif /* CONFIG_KEYS */ | 4393 | #endif /* CONFIG_KEYS */ |
4311 | 4394 | ||
4312 | /* Audit hooks */ | 4395 | /* Audit hooks */ |
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c index bce4e8f1b267..06f719ed63c9 100644 --- a/security/smack/smackfs.c +++ b/security/smack/smackfs.c | |||
@@ -54,6 +54,9 @@ enum smk_inos { | |||
54 | SMK_CHANGE_RULE = 19, /* change or add rules (long labels) */ | 54 | SMK_CHANGE_RULE = 19, /* change or add rules (long labels) */ |
55 | SMK_SYSLOG = 20, /* change syslog label) */ | 55 | SMK_SYSLOG = 20, /* change syslog label) */ |
56 | SMK_PTRACE = 21, /* set ptrace rule */ | 56 | SMK_PTRACE = 21, /* set ptrace rule */ |
57 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | ||
58 | SMK_UNCONFINED = 22, /* define an unconfined label */ | ||
59 | #endif | ||
57 | }; | 60 | }; |
58 | 61 | ||
59 | /* | 62 | /* |
@@ -61,7 +64,6 @@ enum smk_inos { | |||
61 | */ | 64 | */ |
62 | static DEFINE_MUTEX(smack_cipso_lock); | 65 | static DEFINE_MUTEX(smack_cipso_lock); |
63 | static DEFINE_MUTEX(smack_ambient_lock); | 66 | static DEFINE_MUTEX(smack_ambient_lock); |
64 | static DEFINE_MUTEX(smack_syslog_lock); | ||
65 | static DEFINE_MUTEX(smk_netlbladdr_lock); | 67 | static DEFINE_MUTEX(smk_netlbladdr_lock); |
66 | 68 | ||
67 | /* | 69 | /* |
@@ -95,6 +97,16 @@ int smack_cipso_mapped = SMACK_CIPSO_MAPPED_DEFAULT; | |||
95 | */ | 97 | */ |
96 | struct smack_known *smack_onlycap; | 98 | struct smack_known *smack_onlycap; |
97 | 99 | ||
100 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | ||
101 | /* | ||
102 | * Allow one label to be unconfined. This is for | ||
103 | * debugging and application bring-up purposes only. | ||
104 | * It is bad and wrong, but everyone seems to expect | ||
105 | * to have it. | ||
106 | */ | ||
107 | struct smack_known *smack_unconfined; | ||
108 | #endif | ||
109 | |||
98 | /* | 110 | /* |
99 | * If this value is set restrict syslog use to the label specified. | 111 | * If this value is set restrict syslog use to the label specified. |
100 | * It can be reset via smackfs/syslog | 112 | * It can be reset via smackfs/syslog |
@@ -1717,6 +1729,85 @@ static const struct file_operations smk_onlycap_ops = { | |||
1717 | .llseek = default_llseek, | 1729 | .llseek = default_llseek, |
1718 | }; | 1730 | }; |
1719 | 1731 | ||
1732 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | ||
1733 | /** | ||
1734 | * smk_read_unconfined - read() for smackfs/unconfined | ||
1735 | * @filp: file pointer, not actually used | ||
1736 | * @buf: where to put the result | ||
1737 | * @cn: maximum to send along | ||
1738 | * @ppos: where to start | ||
1739 | * | ||
1740 | * Returns number of bytes read or error code, as appropriate | ||
1741 | */ | ||
1742 | static ssize_t smk_read_unconfined(struct file *filp, char __user *buf, | ||
1743 | size_t cn, loff_t *ppos) | ||
1744 | { | ||
1745 | char *smack = ""; | ||
1746 | ssize_t rc = -EINVAL; | ||
1747 | int asize; | ||
1748 | |||
1749 | if (*ppos != 0) | ||
1750 | return 0; | ||
1751 | |||
1752 | if (smack_unconfined != NULL) | ||
1753 | smack = smack_unconfined->smk_known; | ||
1754 | |||
1755 | asize = strlen(smack) + 1; | ||
1756 | |||
1757 | if (cn >= asize) | ||
1758 | rc = simple_read_from_buffer(buf, cn, ppos, smack, asize); | ||
1759 | |||
1760 | return rc; | ||
1761 | } | ||
1762 | |||
1763 | /** | ||
1764 | * smk_write_unconfined - write() for smackfs/unconfined | ||
1765 | * @file: file pointer, not actually used | ||
1766 | * @buf: where to get the data from | ||
1767 | * @count: bytes sent | ||
1768 | * @ppos: where to start | ||
1769 | * | ||
1770 | * Returns number of bytes written or error code, as appropriate | ||
1771 | */ | ||
1772 | static ssize_t smk_write_unconfined(struct file *file, const char __user *buf, | ||
1773 | size_t count, loff_t *ppos) | ||
1774 | { | ||
1775 | char *data; | ||
1776 | int rc = count; | ||
1777 | |||
1778 | if (!smack_privileged(CAP_MAC_ADMIN)) | ||
1779 | return -EPERM; | ||
1780 | |||
1781 | data = kzalloc(count + 1, GFP_KERNEL); | ||
1782 | if (data == NULL) | ||
1783 | return -ENOMEM; | ||
1784 | |||
1785 | /* | ||
1786 | * Should the null string be passed in unset the unconfined value. | ||
1787 | * This seems like something to be careful with as usually | ||
1788 | * smk_import only expects to return NULL for errors. It | ||
1789 | * is usually the case that a nullstring or "\n" would be | ||
1790 | * bad to pass to smk_import but in fact this is useful here. | ||
1791 | * | ||
1792 | * smk_import will also reject a label beginning with '-', | ||
1793 | * so "-confine" will also work. | ||
1794 | */ | ||
1795 | if (copy_from_user(data, buf, count) != 0) | ||
1796 | rc = -EFAULT; | ||
1797 | else | ||
1798 | smack_unconfined = smk_import_entry(data, count); | ||
1799 | |||
1800 | kfree(data); | ||
1801 | return rc; | ||
1802 | } | ||
1803 | |||
1804 | static const struct file_operations smk_unconfined_ops = { | ||
1805 | .read = smk_read_unconfined, | ||
1806 | .write = smk_write_unconfined, | ||
1807 | .llseek = default_llseek, | ||
1808 | }; | ||
1809 | #endif /* CONFIG_SECURITY_SMACK_BRINGUP */ | ||
1810 | |||
1720 | /** | 1811 | /** |
1721 | * smk_read_logging - read() for /smack/logging | 1812 | * smk_read_logging - read() for /smack/logging |
1722 | * @filp: file pointer, not actually used | 1813 | * @filp: file pointer, not actually used |
@@ -2384,6 +2475,10 @@ static int smk_fill_super(struct super_block *sb, void *data, int silent) | |||
2384 | "syslog", &smk_syslog_ops, S_IRUGO|S_IWUSR}, | 2475 | "syslog", &smk_syslog_ops, S_IRUGO|S_IWUSR}, |
2385 | [SMK_PTRACE] = { | 2476 | [SMK_PTRACE] = { |
2386 | "ptrace", &smk_ptrace_ops, S_IRUGO|S_IWUSR}, | 2477 | "ptrace", &smk_ptrace_ops, S_IRUGO|S_IWUSR}, |
2478 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | ||
2479 | [SMK_UNCONFINED] = { | ||
2480 | "unconfined", &smk_unconfined_ops, S_IRUGO|S_IWUSR}, | ||
2481 | #endif | ||
2387 | /* last one */ | 2482 | /* last one */ |
2388 | {""} | 2483 | {""} |
2389 | }; | 2484 | }; |
diff --git a/security/tomoyo/.gitignore b/security/tomoyo/.gitignore index 5caf1a6f5907..dc0f220a210b 100644 --- a/security/tomoyo/.gitignore +++ b/security/tomoyo/.gitignore | |||
@@ -1,2 +1,2 @@ | |||
1 | builtin-policy.h | 1 | builtin-policy.h |
2 | policy/ | 2 | policy/*.conf |
diff --git a/security/tomoyo/Kconfig b/security/tomoyo/Kconfig index 604e718d68d3..404dce66952a 100644 --- a/security/tomoyo/Kconfig +++ b/security/tomoyo/Kconfig | |||
@@ -6,6 +6,7 @@ config SECURITY_TOMOYO | |||
6 | select SECURITY_PATH | 6 | select SECURITY_PATH |
7 | select SECURITY_NETWORK | 7 | select SECURITY_NETWORK |
8 | select SRCU | 8 | select SRCU |
9 | select BUILD_BIN2C | ||
9 | default n | 10 | default n |
10 | help | 11 | help |
11 | This selects TOMOYO Linux, pathname-based access control. | 12 | This selects TOMOYO Linux, pathname-based access control. |
diff --git a/security/tomoyo/Makefile b/security/tomoyo/Makefile index 56a0c7be409e..65dbcb2fd850 100644 --- a/security/tomoyo/Makefile +++ b/security/tomoyo/Makefile | |||
@@ -1,48 +1,15 @@ | |||
1 | obj-y = audit.o common.o condition.o domain.o environ.o file.o gc.o group.o load_policy.o memory.o mount.o network.o realpath.o securityfs_if.o tomoyo.o util.o | 1 | obj-y = audit.o common.o condition.o domain.o environ.o file.o gc.o group.o load_policy.o memory.o mount.o network.o realpath.o securityfs_if.o tomoyo.o util.o |
2 | 2 | ||
3 | $(obj)/policy/profile.conf: | 3 | targets += builtin-policy.h |
4 | @mkdir -p $(obj)/policy/ | 4 | define do_policy |
5 | @echo Creating an empty policy/profile.conf | 5 | echo "static char tomoyo_builtin_$(1)[] __initdata ="; \ |
6 | @touch $@ | 6 | $(objtree)/scripts/basic/bin2c <$(firstword $(wildcard $(obj)/policy/$(1).conf $(srctree)/$(src)/policy/$(1).conf.default) /dev/null); \ |
7 | 7 | echo ";" | |
8 | $(obj)/policy/exception_policy.conf: | 8 | endef |
9 | @mkdir -p $(obj)/policy/ | 9 | quiet_cmd_policy = POLICY $@ |
10 | @echo Creating a default policy/exception_policy.conf | 10 | cmd_policy = ($(call do_policy,profile); $(call do_policy,exception_policy); $(call do_policy,domain_policy); $(call do_policy,manager); $(call do_policy,stat)) >$@ |
11 | @echo initialize_domain /sbin/modprobe from any >> $@ | 11 | |
12 | @echo initialize_domain /sbin/hotplug from any >> $@ | 12 | $(obj)/builtin-policy.h: $(wildcard $(obj)/policy/*.conf $(src)/policy/*.conf.default) FORCE |
13 | 13 | $(call if_changed,policy) | |
14 | $(obj)/policy/domain_policy.conf: | ||
15 | @mkdir -p $(obj)/policy/ | ||
16 | @echo Creating an empty policy/domain_policy.conf | ||
17 | @touch $@ | ||
18 | |||
19 | $(obj)/policy/manager.conf: | ||
20 | @mkdir -p $(obj)/policy/ | ||
21 | @echo Creating an empty policy/manager.conf | ||
22 | @touch $@ | ||
23 | |||
24 | $(obj)/policy/stat.conf: | ||
25 | @mkdir -p $(obj)/policy/ | ||
26 | @echo Creating an empty policy/stat.conf | ||
27 | @touch $@ | ||
28 | |||
29 | $(obj)/builtin-policy.h: $(obj)/policy/profile.conf $(obj)/policy/exception_policy.conf $(obj)/policy/domain_policy.conf $(obj)/policy/manager.conf $(obj)/policy/stat.conf | ||
30 | @echo Generating built-in policy for TOMOYO 2.5.x. | ||
31 | @echo "static char tomoyo_builtin_profile[] __initdata =" > $@.tmp | ||
32 | @sed -e 's/\\/\\\\/g' -e 's/\"/\\"/g' -e 's/\(.*\)/"\1\\n"/' < $(obj)/policy/profile.conf >> $@.tmp | ||
33 | @echo "\"\";" >> $@.tmp | ||
34 | @echo "static char tomoyo_builtin_exception_policy[] __initdata =" >> $@.tmp | ||
35 | @sed -e 's/\\/\\\\/g' -e 's/\"/\\"/g' -e 's/\(.*\)/"\1\\n"/' < $(obj)/policy/exception_policy.conf >> $@.tmp | ||
36 | @echo "\"\";" >> $@.tmp | ||
37 | @echo "static char tomoyo_builtin_domain_policy[] __initdata =" >> $@.tmp | ||
38 | @sed -e 's/\\/\\\\/g' -e 's/\"/\\"/g' -e 's/\(.*\)/"\1\\n"/' < $(obj)/policy/domain_policy.conf >> $@.tmp | ||
39 | @echo "\"\";" >> $@.tmp | ||
40 | @echo "static char tomoyo_builtin_manager[] __initdata =" >> $@.tmp | ||
41 | @sed -e 's/\\/\\\\/g' -e 's/\"/\\"/g' -e 's/\(.*\)/"\1\\n"/' < $(obj)/policy/manager.conf >> $@.tmp | ||
42 | @echo "\"\";" >> $@.tmp | ||
43 | @echo "static char tomoyo_builtin_stat[] __initdata =" >> $@.tmp | ||
44 | @sed -e 's/\\/\\\\/g' -e 's/\"/\\"/g' -e 's/\(.*\)/"\1\\n"/' < $(obj)/policy/stat.conf >> $@.tmp | ||
45 | @echo "\"\";" >> $@.tmp | ||
46 | @mv $@.tmp $@ | ||
47 | 14 | ||
48 | $(obj)/common.o: $(obj)/builtin-policy.h | 15 | $(obj)/common.o: $(obj)/builtin-policy.h |
diff --git a/security/tomoyo/policy/exception_policy.conf.default b/security/tomoyo/policy/exception_policy.conf.default new file mode 100644 index 000000000000..2678df4964ee --- /dev/null +++ b/security/tomoyo/policy/exception_policy.conf.default | |||
@@ -0,0 +1,2 @@ | |||
1 | initialize_domain /sbin/modprobe from any | ||
2 | initialize_domain /sbin/hotplug from any | ||
diff --git a/security/yama/Kconfig b/security/yama/Kconfig index 20ef5143c0c0..3123e1da2fed 100644 --- a/security/yama/Kconfig +++ b/security/yama/Kconfig | |||
@@ -1,8 +1,6 @@ | |||
1 | config SECURITY_YAMA | 1 | config SECURITY_YAMA |
2 | bool "Yama support" | 2 | bool "Yama support" |
3 | depends on SECURITY | 3 | depends on SECURITY |
4 | select SECURITYFS | ||
5 | select SECURITY_PATH | ||
6 | default n | 4 | default n |
7 | help | 5 | help |
8 | This selects Yama, which extends DAC support with additional | 6 | This selects Yama, which extends DAC support with additional |
diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c index 13c88fbcf037..24aae2ae2b30 100644 --- a/security/yama/yama_lsm.c +++ b/security/yama/yama_lsm.c | |||
@@ -379,20 +379,17 @@ static struct security_operations yama_ops = { | |||
379 | static int yama_dointvec_minmax(struct ctl_table *table, int write, | 379 | static int yama_dointvec_minmax(struct ctl_table *table, int write, |
380 | void __user *buffer, size_t *lenp, loff_t *ppos) | 380 | void __user *buffer, size_t *lenp, loff_t *ppos) |
381 | { | 381 | { |
382 | int rc; | 382 | struct ctl_table table_copy; |
383 | 383 | ||
384 | if (write && !capable(CAP_SYS_PTRACE)) | 384 | if (write && !capable(CAP_SYS_PTRACE)) |
385 | return -EPERM; | 385 | return -EPERM; |
386 | 386 | ||
387 | rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos); | ||
388 | if (rc) | ||
389 | return rc; | ||
390 | |||
391 | /* Lock the max value if it ever gets set. */ | 387 | /* Lock the max value if it ever gets set. */ |
392 | if (write && *(int *)table->data == *(int *)table->extra2) | 388 | table_copy = *table; |
393 | table->extra1 = table->extra2; | 389 | if (*(int *)table_copy.data == *(int *)table_copy.extra2) |
390 | table_copy.extra1 = table_copy.extra2; | ||
394 | 391 | ||
395 | return rc; | 392 | return proc_dointvec_minmax(&table_copy, write, buffer, lenp, ppos); |
396 | } | 393 | } |
397 | 394 | ||
398 | static int zero; | 395 | static int zero; |