Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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
...

+1952 -1155
+34
Documentation/devicetree/bindings/security/tpm/st33zp24-spi.txt
··· 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 + };
+79 -50
Documentation/security/Smack.txt
··· 33 33 git://github.com/smack-team/smack.git 34 34 35 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 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 49 In keeping with the intent of Smack, configuration data is 43 50 minimal and not strictly required. The most important ··· 54 47 55 48 Add this line to /etc/fstab: 56 49 57 - smackfs /smack smackfs smackfsdef=* 0 0 50 + smackfs /sys/fs/smackfs smackfs defaults 0 0 58 51 59 - and create the /smack directory for mounting. 52 + The /sys/fs/smackfs directory is created by the kernel. 60 53 61 54 Smack uses extended attributes (xattrs) to store labels on filesystem 62 55 objects. The attributes are stored in the extended attribute security ··· 99 92 # attr -S -s SMACK64 -V "value" path 100 93 # chsmack -a value path 101 94 102 - A process can see the smack label it is running with by 95 + A process can see the Smack label it is running with by 103 96 reading /proc/self/attr/current. A process with CAP_MAC_ADMIN 104 - can set the process smack by writing there. 97 + can set the process Smack by writing there. 105 98 106 99 Most Smack configuration is accomplished by writing to files 107 - in the smackfs filesystem. This pseudo-filesystem is usually 108 - mounted on /smack. 100 + in the smackfs filesystem. This pseudo-filesystem is mounted 101 + on /sys/fs/smackfs. 109 102 110 103 access 111 104 This interface reports whether a subject with the specified ··· 213 206 file or cleared by writing "-" to the file. 214 207 ptrace 215 208 This is used to define the current ptrace policy 216 - 0 - default: this is the policy that relies on smack access rules. 209 + 0 - default: this is the policy that relies on Smack access rules. 217 210 For the PTRACE_READ a subject needs to have a read access on 218 211 object. For the PTRACE_ATTACH a read-write access is required. 219 212 1 - exact: this is the policy that limits PTRACE_ATTACH. Attach is 220 213 only allowed when subject's and object's labels are equal. 221 - PTRACE_READ is not affected. Can be overriden with CAP_SYS_PTRACE. 214 + PTRACE_READ is not affected. Can be overridden with CAP_SYS_PTRACE. 222 215 2 - draconian: this policy behaves like the 'exact' above with an 223 - exception that it can't be overriden with CAP_SYS_PTRACE. 216 + exception that it can't be overridden with CAP_SYS_PTRACE. 224 217 revoke-subject 225 218 Writing a Smack label here sets the access to '-' for all access 226 219 rules with that subject label. 220 + unconfined 221 + If the kernel is configured with CONFIG_SECURITY_SMACK_BRINGUP 222 + a process with CAP_MAC_ADMIN can write a label into this interface. 223 + Thereafter, accesses that involve that label will be logged and 224 + the access permitted if it wouldn't be otherwise. Note that this 225 + is dangerous and can ruin the proper labeling of your system. 226 + It should never be used in production. 227 227 228 228 You can add access rules in /etc/smack/accesses. They take the form: 229 229 230 230 subjectlabel objectlabel access 231 231 232 - access is a combination of the letters rwxa which specify the 232 + access is a combination of the letters rwxatb which specify the 233 233 kind of access permitted a subject with subjectlabel on an 234 234 object with objectlabel. If there is no rule no access is allowed. 235 235 ··· 332 318 333 319 Labels 334 320 335 - Smack labels are ASCII character strings, one to twenty-three characters in 336 - length. Single character labels using special characters, that being anything 321 + Smack labels are ASCII character strings. They can be up to 255 characters 322 + long, but keeping them to twenty-three characters is recommended. 323 + Single character labels using special characters, that being anything 337 324 other than a letter or digit, are reserved for use by the Smack development 338 325 team. Smack labels are unstructured, case sensitive, and the only operation 339 326 ever performed on them is comparison for equality. Smack labels cannot ··· 350 335 ? Pronounced "huh", a single question mark character. 351 336 @ Pronounced "web", a single at sign character. 352 337 353 - Every task on a Smack system is assigned a label. System tasks, such as 354 - init(8) and systems daemons, are run with the floor ("_") label. User tasks 355 - are assigned labels according to the specification found in the 356 - /etc/smack/user configuration file. 338 + Every task on a Smack system is assigned a label. The Smack label 339 + of a process will usually be assigned by the system initialization 340 + mechanism. 357 341 358 342 Access Rules 359 343 ··· 407 393 w: indicates that write access should be granted. 408 394 x: indicates that execute access should be granted. 409 395 t: indicates that the rule requests transmutation. 396 + b: indicates that the rule should be reported for bring-up. 410 397 411 398 Uppercase values for the specification letters are allowed as well. 412 399 Access mode specifications can be in any order. Examples of acceptable rules ··· 417 402 Secret Unclass R 418 403 Manager Game x 419 404 User HR w 405 + Snap Crackle rwxatb 420 406 New Old rRrRr 421 407 Closed Off - 422 408 ··· 429 413 430 414 Spaces are not allowed in labels. Since a subject always has access to files 431 415 with the same label specifying a rule for that case is pointless. Only 432 - valid letters (rwxatRWXAT) and the dash ('-') character are allowed in 416 + valid letters (rwxatbRWXATB) and the dash ('-') character are allowed in 433 417 access specifications. The dash is a placeholder, so "a-r" is the same 434 418 as "ar". A lone dash is used to specify that no access should be allowed. 435 419 ··· 478 462 Setting Access Rules 479 463 480 464 The configuration file /etc/smack/accesses contains the rules to be set at 481 - system startup. The contents are written to the special file /smack/load. 482 - Rules can be written to /smack/load at any time and take effect immediately. 483 - For any pair of subject and object labels there can be only one rule, with the 484 - most recently specified overriding any earlier specification. 485 - 486 - The program smackload is provided to ensure data is formatted 487 - properly when written to /smack/load. This program reads lines 488 - of the form 489 - 490 - subjectlabel objectlabel mode. 465 + system startup. The contents are written to the special file 466 + /sys/fs/smackfs/load2. Rules can be added at any time and take effect 467 + immediately. For any pair of subject and object labels there can be only 468 + one rule, with the most recently specified overriding any earlier 469 + specification. 491 470 492 471 Task Attribute 493 472 ··· 499 488 500 489 Privilege 501 490 502 - A process with CAP_MAC_OVERRIDE is privileged. 491 + A process with CAP_MAC_OVERRIDE or CAP_MAC_ADMIN is privileged. 492 + CAP_MAC_OVERRIDE allows the process access to objects it would 493 + be denied otherwise. CAP_MAC_ADMIN allows a process to change 494 + Smack data, including rules and attributes. 503 495 504 496 Smack Networking 505 497 ··· 524 510 ambient label. 525 511 526 512 Smack requires configuration in the case where packets from a system that is 527 - not smack that speaks CIPSO may be encountered. Usually this will be a Trusted 513 + not Smack that speaks CIPSO may be encountered. Usually this will be a Trusted 528 514 Solaris system, but there are other, less widely deployed systems out there. 529 515 CIPSO provides 3 important values, a Domain Of Interpretation (DOI), a level, 530 516 and a category set with each packet. The DOI is intended to identify a group 531 517 of systems that use compatible labeling schemes, and the DOI specified on the 532 - smack system must match that of the remote system or packets will be 533 - discarded. The DOI is 3 by default. The value can be read from /smack/doi and 534 - can be changed by writing to /smack/doi. 518 + 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 520 + /sys/fs/smackfs/doi and can be changed by writing to /sys/fs/smackfs/doi. 535 521 536 522 The label and category set are mapped to a Smack label as defined in 537 523 /etc/smack/cipso. ··· 553 539 meaning. 554 540 555 541 The mapping of Smack labels to CIPSO values is defined by writing to 556 - /smack/cipso. Again, the format of data written to this special file 557 - is highly restrictive, so the program smackcipso is provided to 558 - ensure the writes are done properly. This program takes mappings 559 - on the standard input and sends them to /smack/cipso properly. 542 + /sys/fs/smackfs/cipso2. 560 543 561 544 In addition to explicit mappings Smack supports direct CIPSO mappings. One 562 545 CIPSO level is used to indicate that the category set passed in the packet is 563 546 in fact an encoding of the Smack label. The level used is 250 by default. The 564 - value can be read from /smack/direct and changed by writing to /smack/direct. 547 + value can be read from /sys/fs/smackfs/direct and changed by writing to 548 + /sys/fs/smackfs/direct. 565 549 566 550 Socket Attributes 567 551 ··· 577 565 Smack Netlabel Exceptions 578 566 579 567 You will often find that your labeled application has to talk to the outside, 580 - unlabeled world. To do this there's a special file /smack/netlabel where you can 581 - add some exceptions in the form of : 568 + unlabeled world. To do this there's a special file /sys/fs/smackfs/netlabel 569 + where you can add some exceptions in the form of : 582 570 @IP1 LABEL1 or 583 571 @IP2/MASK LABEL2 584 572 ··· 586 574 write access on LABEL1, and access to the subnet @IP2/MASK if it has write 587 575 access on LABEL2. 588 576 589 - Entries in the /smack/netlabel file are matched by longest mask first, like in 590 - classless IPv4 routing. 577 + Entries in the /sys/fs/smackfs/netlabel file are matched by longest mask 578 + first, like in classless IPv4 routing. 591 579 592 580 A special label '@' and an option '-CIPSO' can be used there : 593 581 @ means Internet, any application with any label has access to it 594 582 -CIPSO means standard CIPSO networking 595 583 596 584 If you don't know what CIPSO is and don't plan to use it, you can just do : 597 - echo 127.0.0.1 -CIPSO > /smack/netlabel 598 - echo 0.0.0.0/0 @ > /smack/netlabel 585 + echo 127.0.0.1 -CIPSO > /sys/fs/smackfs/netlabel 586 + echo 0.0.0.0/0 @ > /sys/fs/smackfs/netlabel 599 587 600 588 If you use CIPSO on your 192.168.0.0/16 local network and need also unlabeled 601 589 Internet access, you can have : 602 - echo 127.0.0.1 -CIPSO > /smack/netlabel 603 - echo 192.168.0.0/16 -CIPSO > /smack/netlabel 604 - echo 0.0.0.0/0 @ > /smack/netlabel 590 + echo 127.0.0.1 -CIPSO > /sys/fs/smackfs/netlabel 591 + echo 192.168.0.0/16 -CIPSO > /sys/fs/smackfs/netlabel 592 + echo 0.0.0.0/0 @ > /sys/fs/smackfs/netlabel 605 593 606 594 607 595 Writing Applications for Smack ··· 688 676 If you want Smack auditing of security events, you need to set CONFIG_AUDIT 689 677 in your kernel configuration. 690 678 By default, all denied events will be audited. You can change this behavior by 691 - writing a single character to the /smack/logging file : 679 + writing a single character to the /sys/fs/smackfs/logging file : 692 680 0 : no logging 693 681 1 : log denied (default) 694 682 2 : log accepted ··· 698 686 the subject, the object, the rights requested, the action, the kernel function 699 687 that triggered the event, plus other pairs depending on the type of event 700 688 audited. 689 + 690 + Bringup Mode 691 + 692 + Bringup mode provides logging features that can make application 693 + configuration and system bringup easier. Configure the kernel with 694 + CONFIG_SECURITY_SMACK_BRINGUP to enable these features. When bringup 695 + mode is enabled accesses that succeed due to rules marked with the "b" 696 + access mode will logged. When a new label is introduced for processes 697 + rules can be added aggressively, marked with the "b". The logging allows 698 + tracking of which rules actual get used for that label. 699 + 700 + Another feature of bringup mode is the "unconfined" option. Writing 701 + a label to /sys/fs/smackfs/unconfined makes subjects with that label 702 + able to access any object, and objects with that label accessible to 703 + all subjects. Any access that is granted because a label is unconfined 704 + is logged. This feature is dangerous, as files and directories may 705 + be created in places they couldn't if the policy were being enforced.
+1
MAINTAINERS
··· 9968 9968 TPM DEVICE DRIVER 9969 9969 M: Peter Huewe <peterhuewe@gmx.de> 9970 9970 M: Marcel Selhorst <tpmdd@selhorst.net> 9971 + R: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> 9971 9972 W: http://tpmdd.sourceforge.net 9972 9973 L: tpmdd-devel@lists.sourceforge.net (moderated for non-subscribers) 9973 9974 Q: git git://github.com/PeterHuewe/linux-tpmdd.git
+6 -14
drivers/char/tpm/Kconfig
··· 25 25 if TCG_TPM 26 26 27 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 29 depends on X86 30 30 ---help--- 31 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 33 - from within Linux. To compile this driver as a module, choose 34 - M here; the module will be called tpm_tis. 32 + TCG TIS 1.2 TPM specification (TPM1.2) or the TCG PTP FIFO 33 + specification (TPM2.0) say Yes and it will be accessible from 34 + within Linux. To compile this driver as a module, choose M here; 35 + the module will be called tpm_tis. 35 36 36 37 config TCG_TIS_I2C_ATMEL 37 38 tristate "TPM Interface Specification 1.2 Interface (I2C - Atmel)" ··· 101 100 will be accessible from within Linux. To compile this driver 102 101 as a module, choose M here; the module will be called tpm_ibmvtpm. 103 102 104 - config TCG_TIS_I2C_ST33 105 - tristate "TPM Interface Specification 1.2 Interface (I2C - STMicroelectronics)" 106 - depends on I2C 107 - depends on GPIOLIB 108 - ---help--- 109 - If you have a TPM security chip from STMicroelectronics working with 110 - an I2C bus say Yes and it will be accessible from within Linux. 111 - To compile this driver as a module, choose M here; the module will be 112 - called tpm_i2c_stm_st33. 113 - 114 103 config TCG_XEN 115 104 tristate "XEN TPM Interface" 116 105 depends on TCG_TPM && XEN ··· 122 131 from within Linux. To compile this driver as a module, choose 123 132 M here; the module will be called tpm_crb. 124 133 134 + source "drivers/char/tpm/st33zp24/Kconfig" 125 135 endif # TCG_TPM
+1 -1
drivers/char/tpm/Makefile
··· 20 20 obj-$(CONFIG_TCG_ATMEL) += tpm_atmel.o 21 21 obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o 22 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 24 obj-$(CONFIG_TCG_XEN) += xen-tpmfront.o 25 25 obj-$(CONFIG_TCG_CRB) += tpm_crb.o
+30
drivers/char/tpm/st33zp24/Kconfig
··· 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.
+12
drivers/char/tpm/st33zp24/Makefile
··· 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
+276
drivers/char/tpm/st33zp24/i2c.c
··· 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");
+399
drivers/char/tpm/st33zp24/spi.c
··· 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");
+698
drivers/char/tpm/st33zp24/st33zp24.c
··· 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");
+37
drivers/char/tpm/st33zp24/st33zp24.h
··· 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__ */
+42 -24
drivers/char/tpm/tpm-chip.c
··· 170 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 209 * tpm_chip_register() - create a character device for the TPM chip 175 210 * @chip: TPM chip to use. ··· 220 185 { 221 186 int rc; 222 187 223 - /* Populate sysfs for TPM1 devices. */ 224 - if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { 225 - rc = tpm_sysfs_add_device(chip); 226 - if (rc) 227 - goto del_misc; 228 - 229 - rc = tpm_add_ppi(chip); 230 - if (rc) 231 - goto del_sysfs; 232 - 233 - chip->bios_dir = tpm_bios_log_setup(chip->devname); 234 - } 188 + rc = tpm1_chip_register(chip); 189 + if (rc) 190 + return rc; 235 191 236 192 rc = tpm_dev_add_device(chip); 237 193 if (rc) 238 - return rc; 194 + goto out_err; 239 195 240 196 /* Make the chip available. */ 241 197 spin_lock(&driver_lock); ··· 236 210 chip->flags |= TPM_CHIP_FLAG_REGISTERED; 237 211 238 212 return 0; 239 - del_sysfs: 240 - tpm_sysfs_del_device(chip); 241 - del_misc: 242 - tpm_dev_del_device(chip); 213 + out_err: 214 + tpm1_chip_unregister(chip); 243 215 return rc; 244 216 } 245 217 EXPORT_SYMBOL_GPL(tpm_chip_register); ··· 262 238 spin_unlock(&driver_lock); 263 239 synchronize_rcu(); 264 240 265 - if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { 266 - if (chip->bios_dir) 267 - tpm_bios_log_teardown(chip->bios_dir); 268 - tpm_remove_ppi(chip); 269 - tpm_sysfs_del_device(chip); 270 - } 271 - 241 + tpm1_chip_unregister(chip); 272 242 tpm_dev_del_device(chip); 273 243 } 274 244 EXPORT_SYMBOL_GPL(tpm_chip_unregister);
-911
drivers/char/tpm/tpm_i2c_stm_st33.c
··· 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");
+9 -25
drivers/char/tpm/tpm_infineon.c
··· 591 591 } 592 592 } 593 593 594 - static int tpm_inf_pnp_suspend(struct pnp_dev *dev, pm_message_t pm_state) 595 - { 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) 594 + #ifdef CONFIG_PM_SLEEP 595 + static int tpm_inf_resume(struct device *dev) 615 596 { 616 597 /* Re-configure TPM after suspending */ 617 598 tpm_config_out(ENABLE_REGISTER_PAIR, TPM_INF_ADDR); ··· 606 625 tpm_config_out(DISABLE_REGISTER_PAIR, TPM_INF_ADDR); 607 626 /* disable RESET, LP and IRQC */ 608 627 tpm_data_out(RESET_LP_IRQC_DISABLE, CMD); 609 - return tpm_pm_resume(&dev->dev); 628 + return tpm_pm_resume(dev); 610 629 } 630 + #endif 631 + static SIMPLE_DEV_PM_OPS(tpm_inf_pm, tpm_pm_suspend, tpm_inf_resume); 611 632 612 633 static struct pnp_driver tpm_inf_pnp_driver = { 613 634 .name = "tpm_inf_pnp", 614 635 .id_table = tpm_inf_pnp_tbl, 615 636 .probe = tpm_inf_pnp_probe, 616 - .suspend = tpm_inf_pnp_suspend, 617 - .resume = tpm_inf_pnp_resume, 618 - .remove = tpm_inf_pnp_remove 637 + .remove = tpm_inf_pnp_remove, 638 + .driver = { 639 + .pm = &tpm_inf_pm, 640 + } 619 641 }; 620 642 621 643 module_pnp_driver(tpm_inf_pnp_driver);
+5 -16
include/linux/platform_data/tpm_stm_st33.h include/linux/platform_data/st33zp24.h
··· 1 1 /* 2 - * STMicroelectronics TPM I2C Linux driver for TPM ST33ZP24 3 - * Copyright (C) 2009, 2010 STMicroelectronics 2 + * STMicroelectronics TPM Linux driver for TPM 1.2 ST33ZP24 3 + * Copyright (C) 2009 - 2015 STMicroelectronics 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify 6 6 * it under the terms of the GNU General Public License as published by ··· 14 14 * 15 15 * You should have received a copy of the GNU General Public License 16 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__ 30 - #define __STM_ST33_TPM_H__ 18 + #ifndef __ST33ZP24_H__ 19 + #define __ST33ZP24_H__ 31 20 32 21 #define TPM_ST33_I2C "st33zp24-i2c" 33 22 #define TPM_ST33_SPI "st33zp24-spi" ··· 25 36 int io_lpcpd; 26 37 }; 27 38 28 - #endif /* __STM_ST33_TPM_H__ */ 39 + #endif /* __ST33ZP24_H__ */
+9 -6
security/lsm_audit.c
··· 211 211 static void dump_common_audit_data(struct audit_buffer *ab, 212 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 217 * To keep stack sizes in check force programers to notice if they ··· 220 220 */ 221 221 BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2); 222 222 223 - audit_log_format(ab, " pid=%d comm=", task_pid_nr(tsk)); 224 - audit_log_untrustedstring(ab, tsk->comm); 223 + audit_log_format(ab, " pid=%d comm=", task_pid_nr(current)); 224 + audit_log_untrustedstring(ab, memcpy(comm, current->comm, sizeof(comm))); 225 225 226 226 switch (a->type) { 227 227 case LSM_AUDIT_DATA_NONE: ··· 276 276 audit_log_format(ab, " ino=%lu", inode->i_ino); 277 277 break; 278 278 } 279 - case LSM_AUDIT_DATA_TASK: 280 - tsk = a->u.tsk; 279 + case LSM_AUDIT_DATA_TASK: { 280 + struct task_struct *tsk = a->u.tsk; 281 281 if (tsk) { 282 282 pid_t pid = task_pid_nr(tsk); 283 283 if (pid) { 284 + char comm[sizeof(tsk->comm)]; 284 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 290 break; 291 + } 289 292 case LSM_AUDIT_DATA_NET: 290 293 if (a->u.net->sk) { 291 294 struct sock *sk = a->u.net->sk;
+2 -4
security/selinux/avc.c
··· 724 724 rcu_read_lock(); 725 725 726 726 node = avc_lookup(ssid, tsid, tclass); 727 - if (unlikely(!node)) { 727 + if (unlikely(!node)) 728 728 node = avc_compute_av(ssid, tsid, tclass, avd); 729 - } else { 729 + else 730 730 memcpy(avd, &node->ae.avd, sizeof(*avd)); 731 - avd = &node->ae.avd; 732 - } 733 731 734 732 denied = requested & ~(avd->allowed); 735 733 if (unlikely(denied))
+56 -16
security/selinux/ss/avtab.c
··· 25 25 26 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) + 31 - (keyp->source_type << 9)) & mask); 33 + static const u32 c1 = 0xcc9e2d51; 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 67 static struct avtab_node* ··· 79 46 newnode->next = prev->next; 80 47 prev->next = newnode; 81 48 } else { 82 - newnode->next = h->htable[hvalue]; 83 - h->htable[hvalue] = newnode; 49 + newnode->next = flex_array_get_ptr(h->htable, hvalue); 50 + if (flex_array_put_ptr(h->htable, hvalue, newnode, 51 + GFP_KERNEL|__GFP_ZERO)) { 52 + kmem_cache_free(avtab_node_cachep, newnode); 53 + return NULL; 54 + } 84 55 } 85 56 86 57 h->nel++; ··· 101 64 return -EINVAL; 102 65 103 66 hvalue = avtab_hash(key, h->mask); 104 - for (prev = NULL, cur = h->htable[hvalue]; 67 + for (prev = NULL, cur = flex_array_get_ptr(h->htable, hvalue); 105 68 cur; 106 69 prev = cur, cur = cur->next) { 107 70 if (key->source_type == cur->key.source_type && ··· 141 104 if (!h || !h->htable) 142 105 return NULL; 143 106 hvalue = avtab_hash(key, h->mask); 144 - for (prev = NULL, cur = h->htable[hvalue]; 107 + for (prev = NULL, cur = flex_array_get_ptr(h->htable, hvalue); 145 108 cur; 146 109 prev = cur, cur = cur->next) { 147 110 if (key->source_type == cur->key.source_type && ··· 172 135 return NULL; 173 136 174 137 hvalue = avtab_hash(key, h->mask); 175 - for (cur = h->htable[hvalue]; cur; cur = cur->next) { 138 + for (cur = flex_array_get_ptr(h->htable, hvalue); cur; 139 + cur = cur->next) { 176 140 if (key->source_type == cur->key.source_type && 177 141 key->target_type == cur->key.target_type && 178 142 key->target_class == cur->key.target_class && ··· 208 170 return NULL; 209 171 210 172 hvalue = avtab_hash(key, h->mask); 211 - for (cur = h->htable[hvalue]; cur; cur = cur->next) { 173 + for (cur = flex_array_get_ptr(h->htable, hvalue); cur; 174 + cur = cur->next) { 212 175 if (key->source_type == cur->key.source_type && 213 176 key->target_type == cur->key.target_type && 214 177 key->target_class == cur->key.target_class && ··· 267 228 return; 268 229 269 230 for (i = 0; i < h->nslot; i++) { 270 - cur = h->htable[i]; 231 + cur = flex_array_get_ptr(h->htable, i); 271 232 while (cur) { 272 233 temp = cur; 273 234 cur = cur->next; 274 235 kmem_cache_free(avtab_node_cachep, temp); 275 236 } 276 - h->htable[i] = NULL; 277 237 } 278 - kfree(h->htable); 238 + flex_array_free(h->htable); 279 239 h->htable = NULL; 280 240 h->nslot = 0; 281 241 h->mask = 0; ··· 289 251 290 252 int avtab_alloc(struct avtab *h, u32 nrules) 291 253 { 292 - u16 mask = 0; 254 + u32 mask = 0; 293 255 u32 shift = 0; 294 256 u32 work = nrules; 295 257 u32 nslot = 0; ··· 308 270 nslot = MAX_AVTAB_HASH_BUCKETS; 309 271 mask = nslot - 1; 310 272 311 - h->htable = kcalloc(nslot, sizeof(*(h->htable)), GFP_KERNEL); 273 + h->htable = flex_array_alloc(sizeof(struct avtab_node *), nslot, 274 + GFP_KERNEL | __GFP_ZERO); 312 275 if (!h->htable) 313 276 return -ENOMEM; 314 277 ··· 332 293 max_chain_len = 0; 333 294 chain2_len_sum = 0; 334 295 for (i = 0; i < h->nslot; i++) { 335 - cur = h->htable[i]; 296 + cur = flex_array_get_ptr(h->htable, i); 336 297 if (cur) { 337 298 slots_used++; 338 299 chain_len = 0; ··· 573 534 return rc; 574 535 575 536 for (i = 0; i < a->nslot; i++) { 576 - for (cur = a->htable[i]; cur; cur = cur->next) { 537 + for (cur = flex_array_get_ptr(a->htable, i); cur; 538 + cur = cur->next) { 577 539 rc = avtab_write_item(p, cur, fp); 578 540 if (rc) 579 541 return rc;
+5 -3
security/selinux/ss/avtab.h
··· 23 23 #ifndef _SS_AVTAB_H_ 24 24 #define _SS_AVTAB_H_ 25 25 26 + #include <linux/flex_array.h> 27 + 26 28 struct avtab_key { 27 29 u16 source_type; /* source type */ 28 30 u16 target_type; /* target type */ ··· 53 51 }; 54 52 55 53 struct avtab { 56 - struct avtab_node **htable; 54 + struct flex_array *htable; 57 55 u32 nel; /* number of elements */ 58 56 u32 nslot; /* number of hash slots */ 59 - u16 mask; /* mask to compute hash func */ 57 + u32 mask; /* mask to compute hash func */ 60 58 61 59 }; 62 60 ··· 86 84 void avtab_cache_init(void); 87 85 void avtab_cache_destroy(void); 88 86 89 - #define MAX_AVTAB_HASH_BITS 11 87 + #define MAX_AVTAB_HASH_BITS 16 90 88 #define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS) 91 89 92 90 #endif /* _SS_AVTAB_H_ */
+3 -7
security/selinux/ss/mls.c
··· 654 654 655 655 rc = ebitmap_netlbl_import(&context->range.level[0].cat, 656 656 secattr->attr.mls.cat); 657 - if (rc != 0) 657 + if (rc) 658 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; 659 + memcpy(&context->range.level[1].cat, &context->range.level[0].cat, 660 + sizeof(context->range.level[0].cat)); 664 661 665 662 return 0; 666 663 667 664 import_netlbl_cat_failure: 668 665 ebitmap_destroy(&context->range.level[0].cat); 669 - ebitmap_destroy(&context->range.level[1].cat); 670 666 return rc; 671 667 } 672 668 #endif /* CONFIG_NETLABEL */
+1 -5
security/selinux/ss/services.c
··· 3179 3179 ctx_new.type = ctx->type; 3180 3180 mls_import_netlbl_lvl(&ctx_new, secattr); 3181 3181 if (secattr->flags & NETLBL_SECATTR_MLS_CAT) { 3182 - rc = ebitmap_netlbl_import(&ctx_new.range.level[0].cat, 3183 - secattr->attr.mls.cat); 3182 + rc = mls_import_netlbl_cat(&ctx_new, secattr); 3184 3183 if (rc) 3185 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 3186 rc = -EIDRM; 3191 3187 if (!mls_context_isvalid(&policydb, &ctx_new))
+8
security/smack/smack.h
··· 105 105 #define SMK_INODE_INSTANT 0x01 /* inode is instantiated */ 106 106 #define SMK_INODE_TRANSMUTE 0x02 /* directory is transmuting */ 107 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 111 * A label access rule. ··· 194 193 #define MAY_LOCK 0x00002000 /* Locks should be writes, but ... */ 195 194 #define MAY_BRINGUP 0x00004000 /* Report use of this rule */ 196 195 196 + #define SMACK_BRINGUP_ALLOW 1 /* Allow bringup mode */ 197 + #define SMACK_UNCONFINED_SUBJECT 2 /* Allow unconfined label */ 198 + #define SMACK_UNCONFINED_OBJECT 3 /* Allow unconfined label */ 199 + 197 200 /* 198 201 * Just to make the common cases easier to deal with 199 202 */ ··· 259 254 extern struct smack_known *smack_net_ambient; 260 255 extern struct smack_known *smack_onlycap; 261 256 extern struct smack_known *smack_syslog_label; 257 + #ifdef CONFIG_SECURITY_SMACK_BRINGUP 258 + extern struct smack_known *smack_unconfined; 259 + #endif 262 260 extern struct smack_known smack_cipso_option; 263 261 extern int smack_ptrace_rule; 264 262
+33 -10
security/smack/smack_access.c
··· 130 130 131 131 /* 132 132 * Hardcoded comparisons. 133 - * 133 + */ 134 + /* 134 135 * A star subject can't access any object. 135 136 */ 136 137 if (subject == &smack_known_star) { ··· 190 189 * succeed because of "b" rules. 191 190 */ 192 191 if (may & MAY_BRINGUP) 193 - rc = MAY_BRINGUP; 192 + rc = SMACK_BRINGUP_ALLOW; 194 193 #endif 195 194 196 195 out_audit: 196 + 197 + #ifdef CONFIG_SECURITY_SMACK_BRINGUP 198 + if (rc < 0) { 199 + if (object == smack_unconfined) 200 + rc = SMACK_UNCONFINED_OBJECT; 201 + if (subject == smack_unconfined) 202 + rc = SMACK_UNCONFINED_SUBJECT; 203 + } 204 + #endif 205 + 197 206 #ifdef CONFIG_AUDIT 198 207 if (a) 199 208 smack_log(subject->smk_known, object->smk_known, ··· 349 338 void smack_log(char *subject_label, char *object_label, int request, 350 339 int result, struct smk_audit_info *ad) 351 340 { 341 + #ifdef CONFIG_SECURITY_SMACK_BRINGUP 342 + char request_buffer[SMK_NUM_ACCESS_TYPE + 5]; 343 + #else 352 344 char request_buffer[SMK_NUM_ACCESS_TYPE + 1]; 345 + #endif 353 346 struct smack_audit_data *sad; 354 347 struct common_audit_data *a = &ad->a; 355 348 356 - #ifdef CONFIG_SECURITY_SMACK_BRINGUP 357 - /* 358 - * The result may be positive in bringup mode. 359 - */ 360 - if (result > 0) 361 - result = 0; 362 - #endif 363 349 /* check if we have to log the current event */ 364 - if (result != 0 && (log_policy & SMACK_AUDIT_DENIED) == 0) 350 + if (result < 0 && (log_policy & SMACK_AUDIT_DENIED) == 0) 365 351 return; 366 352 if (result == 0 && (log_policy & SMACK_AUDIT_ACCEPT) == 0) 367 353 return; ··· 372 364 smack_str_from_perm(request_buffer, request); 373 365 sad->subject = subject_label; 374 366 sad->object = object_label; 367 + #ifdef CONFIG_SECURITY_SMACK_BRINGUP 368 + /* 369 + * The result may be positive in bringup mode. 370 + * A positive result is an allow, but not for normal reasons. 371 + * Mark it as successful, but don't filter it out even if 372 + * the logging policy says to do so. 373 + */ 374 + if (result == SMACK_UNCONFINED_SUBJECT) 375 + strcat(request_buffer, "(US)"); 376 + else if (result == SMACK_UNCONFINED_OBJECT) 377 + strcat(request_buffer, "(UO)"); 378 + 379 + if (result > 0) 380 + result = 0; 381 + #endif 375 382 sad->request = request_buffer; 376 383 sad->result = result; 377 384
+91 -8
security/smack/smack_lsm.c
··· 57 57 int smack_enabled; 58 58 59 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 67 static void smk_bu_mode(int mode, char *s) 61 68 { 62 69 int i = 0; ··· 94 87 95 88 if (rc <= 0) 96 89 return rc; 90 + if (rc > SMACK_UNCONFINED_OBJECT) 91 + rc = 0; 97 92 98 93 smk_bu_mode(mode, acc); 99 - pr_info("Smack Bringup: (%s %s %s) %s\n", 94 + pr_info("Smack %s: (%s %s %s) %s\n", smk_bu_mess[rc], 100 95 sskp->smk_known, oskp->smk_known, acc, note); 101 96 return 0; 102 97 } ··· 115 106 116 107 if (rc <= 0) 117 108 return rc; 109 + if (rc > SMACK_UNCONFINED_OBJECT) 110 + rc = 0; 118 111 119 112 smk_bu_mode(mode, acc); 120 - pr_info("Smack Bringup: (%s %s %s) %s %s\n", 113 + pr_info("Smack %s: (%s %s %s) %s %s\n", smk_bu_mess[rc], 121 114 tsp->smk_task->smk_known, oskp->smk_known, 122 115 acc, current->comm, note); 123 116 return 0; ··· 137 126 138 127 if (rc <= 0) 139 128 return rc; 129 + if (rc > SMACK_UNCONFINED_OBJECT) 130 + rc = 0; 140 131 141 132 smk_bu_mode(mode, acc); 142 - pr_info("Smack Bringup: (%s %s %s) %s to %s\n", 133 + pr_info("Smack %s: (%s %s %s) %s to %s\n", smk_bu_mess[rc], 143 134 tsp->smk_task->smk_known, smk_task->smk_known, acc, 144 135 current->comm, otp->comm); 145 136 return 0; ··· 154 141 static int smk_bu_inode(struct inode *inode, int mode, int rc) 155 142 { 156 143 struct task_smack *tsp = current_security(); 144 + struct inode_smack *isp = inode->i_security; 157 145 char acc[SMK_NUM_ACCESS_TYPE + 1]; 146 + 147 + if (isp->smk_flags & SMK_INODE_IMPURE) 148 + pr_info("Smack Unconfined Corruption: inode=(%s %ld) %s\n", 149 + inode->i_sb->s_id, inode->i_ino, current->comm); 158 150 159 151 if (rc <= 0) 160 152 return rc; 153 + if (rc > SMACK_UNCONFINED_OBJECT) 154 + rc = 0; 155 + if (rc == SMACK_UNCONFINED_SUBJECT && 156 + (mode & (MAY_WRITE | MAY_APPEND))) 157 + isp->smk_flags |= SMK_INODE_IMPURE; 161 158 162 159 smk_bu_mode(mode, acc); 163 - pr_info("Smack Bringup: (%s %s %s) inode=(%s %ld) %s\n", 164 - tsp->smk_task->smk_known, smk_of_inode(inode)->smk_known, acc, 160 + 161 + pr_info("Smack %s: (%s %s %s) inode=(%s %ld) %s\n", smk_bu_mess[rc], 162 + tsp->smk_task->smk_known, isp->smk_inode->smk_known, acc, 165 163 inode->i_sb->s_id, inode->i_ino, current->comm); 166 164 return 0; 167 165 } ··· 186 162 struct task_smack *tsp = current_security(); 187 163 struct smack_known *sskp = tsp->smk_task; 188 164 struct inode *inode = file_inode(file); 165 + struct inode_smack *isp = inode->i_security; 189 166 char acc[SMK_NUM_ACCESS_TYPE + 1]; 167 + 168 + if (isp->smk_flags & SMK_INODE_IMPURE) 169 + pr_info("Smack Unconfined Corruption: inode=(%s %ld) %s\n", 170 + inode->i_sb->s_id, inode->i_ino, current->comm); 190 171 191 172 if (rc <= 0) 192 173 return rc; 174 + if (rc > SMACK_UNCONFINED_OBJECT) 175 + rc = 0; 193 176 194 177 smk_bu_mode(mode, acc); 195 - pr_info("Smack Bringup: (%s %s %s) file=(%s %ld %pD) %s\n", 178 + pr_info("Smack %s: (%s %s %s) file=(%s %ld %pD) %s\n", smk_bu_mess[rc], 196 179 sskp->smk_known, smk_of_inode(inode)->smk_known, acc, 197 180 inode->i_sb->s_id, inode->i_ino, file, 198 181 current->comm); ··· 216 185 struct task_smack *tsp = cred->security; 217 186 struct smack_known *sskp = tsp->smk_task; 218 187 struct inode *inode = file->f_inode; 188 + struct inode_smack *isp = inode->i_security; 219 189 char acc[SMK_NUM_ACCESS_TYPE + 1]; 190 + 191 + if (isp->smk_flags & SMK_INODE_IMPURE) 192 + pr_info("Smack Unconfined Corruption: inode=(%s %ld) %s\n", 193 + inode->i_sb->s_id, inode->i_ino, current->comm); 220 194 221 195 if (rc <= 0) 222 196 return rc; 197 + if (rc > SMACK_UNCONFINED_OBJECT) 198 + rc = 0; 223 199 224 200 smk_bu_mode(mode, acc); 225 - pr_info("Smack Bringup: (%s %s %s) file=(%s %ld %pD) %s\n", 201 + pr_info("Smack %s: (%s %s %s) file=(%s %ld %pD) %s\n", smk_bu_mess[rc], 226 202 sskp->smk_known, smk_of_inode(inode)->smk_known, acc, 227 203 inode->i_sb->s_id, inode->i_ino, file, 228 204 current->comm); ··· 2487 2449 static int smack_socket_post_create(struct socket *sock, int family, 2488 2450 int type, int protocol, int kern) 2489 2451 { 2490 - if (family != PF_INET || sock->sk == NULL) 2452 + struct socket_smack *ssp; 2453 + 2454 + if (sock->sk == NULL) 2455 + return 0; 2456 + 2457 + /* 2458 + * Sockets created by kernel threads receive web label. 2459 + */ 2460 + if (unlikely(current->flags & PF_KTHREAD)) { 2461 + ssp = sock->sk->sk_security; 2462 + ssp->smk_in = &smack_known_web; 2463 + ssp->smk_out = &smack_known_web; 2464 + } 2465 + 2466 + if (family != PF_INET) 2491 2467 return 0; 2492 2468 /* 2493 2469 * Set the outbound netlbl. ··· 4035 3983 rc = smk_bu_note("key access", tkp, keyp->security, request, rc); 4036 3984 return rc; 4037 3985 } 3986 + 3987 + /* 3988 + * smack_key_getsecurity - Smack label tagging the key 3989 + * @key points to the key to be queried 3990 + * @_buffer points to a pointer that should be set to point to the 3991 + * resulting string (if no label or an error occurs). 3992 + * Return the length of the string (including terminating NUL) or -ve if 3993 + * an error. 3994 + * May also return 0 (and a NULL buffer pointer) if there is no label. 3995 + */ 3996 + static int smack_key_getsecurity(struct key *key, char **_buffer) 3997 + { 3998 + struct smack_known *skp = key->security; 3999 + size_t length; 4000 + char *copy; 4001 + 4002 + if (key->security == NULL) { 4003 + *_buffer = NULL; 4004 + return 0; 4005 + } 4006 + 4007 + copy = kstrdup(skp->smk_known, GFP_KERNEL); 4008 + if (copy == NULL) 4009 + return -ENOMEM; 4010 + length = strlen(copy) + 1; 4011 + 4012 + *_buffer = copy; 4013 + return length; 4014 + } 4015 + 4038 4016 #endif /* CONFIG_KEYS */ 4039 4017 4040 4018 /* ··· 4389 4307 .key_alloc = smack_key_alloc, 4390 4308 .key_free = smack_key_free, 4391 4309 .key_permission = smack_key_permission, 4310 + .key_getsecurity = smack_key_getsecurity, 4392 4311 #endif /* CONFIG_KEYS */ 4393 4312 4394 4313 /* Audit hooks */
+96 -1
security/smack/smackfs.c
··· 54 54 SMK_CHANGE_RULE = 19, /* change or add rules (long labels) */ 55 55 SMK_SYSLOG = 20, /* change syslog label) */ 56 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 /* ··· 64 61 */ 65 62 static DEFINE_MUTEX(smack_cipso_lock); 66 63 static DEFINE_MUTEX(smack_ambient_lock); 67 - static DEFINE_MUTEX(smack_syslog_lock); 68 64 static DEFINE_MUTEX(smk_netlbladdr_lock); 69 65 70 66 /* ··· 96 94 * will be used if any label is used. 97 95 */ 98 96 struct smack_known *smack_onlycap; 97 + 98 + #ifdef CONFIG_SECURITY_SMACK_BRINGUP 99 + /* 100 + * Allow one label to be unconfined. This is for 101 + * debugging and application bring-up purposes only. 102 + * It is bad and wrong, but everyone seems to expect 103 + * to have it. 104 + */ 105 + struct smack_known *smack_unconfined; 106 + #endif 99 107 100 108 /* 101 109 * If this value is set restrict syslog use to the label specified. ··· 1729 1717 .llseek = default_llseek, 1730 1718 }; 1731 1719 1720 + #ifdef CONFIG_SECURITY_SMACK_BRINGUP 1721 + /** 1722 + * smk_read_unconfined - read() for smackfs/unconfined 1723 + * @filp: file pointer, not actually used 1724 + * @buf: where to put the result 1725 + * @cn: maximum to send along 1726 + * @ppos: where to start 1727 + * 1728 + * Returns number of bytes read or error code, as appropriate 1729 + */ 1730 + static ssize_t smk_read_unconfined(struct file *filp, char __user *buf, 1731 + size_t cn, loff_t *ppos) 1732 + { 1733 + char *smack = ""; 1734 + ssize_t rc = -EINVAL; 1735 + int asize; 1736 + 1737 + if (*ppos != 0) 1738 + return 0; 1739 + 1740 + if (smack_unconfined != NULL) 1741 + smack = smack_unconfined->smk_known; 1742 + 1743 + asize = strlen(smack) + 1; 1744 + 1745 + if (cn >= asize) 1746 + rc = simple_read_from_buffer(buf, cn, ppos, smack, asize); 1747 + 1748 + return rc; 1749 + } 1750 + 1751 + /** 1752 + * smk_write_unconfined - write() for smackfs/unconfined 1753 + * @file: file pointer, not actually used 1754 + * @buf: where to get the data from 1755 + * @count: bytes sent 1756 + * @ppos: where to start 1757 + * 1758 + * Returns number of bytes written or error code, as appropriate 1759 + */ 1760 + static ssize_t smk_write_unconfined(struct file *file, const char __user *buf, 1761 + size_t count, loff_t *ppos) 1762 + { 1763 + char *data; 1764 + int rc = count; 1765 + 1766 + if (!smack_privileged(CAP_MAC_ADMIN)) 1767 + return -EPERM; 1768 + 1769 + data = kzalloc(count + 1, GFP_KERNEL); 1770 + if (data == NULL) 1771 + return -ENOMEM; 1772 + 1773 + /* 1774 + * Should the null string be passed in unset the unconfined value. 1775 + * This seems like something to be careful with as usually 1776 + * smk_import only expects to return NULL for errors. It 1777 + * is usually the case that a nullstring or "\n" would be 1778 + * bad to pass to smk_import but in fact this is useful here. 1779 + * 1780 + * smk_import will also reject a label beginning with '-', 1781 + * so "-confine" will also work. 1782 + */ 1783 + if (copy_from_user(data, buf, count) != 0) 1784 + rc = -EFAULT; 1785 + else 1786 + smack_unconfined = smk_import_entry(data, count); 1787 + 1788 + kfree(data); 1789 + return rc; 1790 + } 1791 + 1792 + static const struct file_operations smk_unconfined_ops = { 1793 + .read = smk_read_unconfined, 1794 + .write = smk_write_unconfined, 1795 + .llseek = default_llseek, 1796 + }; 1797 + #endif /* CONFIG_SECURITY_SMACK_BRINGUP */ 1798 + 1732 1799 /** 1733 1800 * smk_read_logging - read() for /smack/logging 1734 1801 * @filp: file pointer, not actually used ··· 2475 2384 "syslog", &smk_syslog_ops, S_IRUGO|S_IWUSR}, 2476 2385 [SMK_PTRACE] = { 2477 2386 "ptrace", &smk_ptrace_ops, S_IRUGO|S_IWUSR}, 2387 + #ifdef CONFIG_SECURITY_SMACK_BRINGUP 2388 + [SMK_UNCONFINED] = { 2389 + "unconfined", &smk_unconfined_ops, S_IRUGO|S_IWUSR}, 2390 + #endif 2478 2391 /* last one */ 2479 2392 {""} 2480 2393 };
+1 -1
security/tomoyo/.gitignore
··· 1 1 builtin-policy.h 2 - policy/ 2 + policy/*.conf
+1
security/tomoyo/Kconfig
··· 6 6 select SECURITY_PATH 7 7 select SECURITY_NETWORK 8 8 select SRCU 9 + select BUILD_BIN2C 9 10 default n 10 11 help 11 12 This selects TOMOYO Linux, pathname-based access control.
+10 -43
security/tomoyo/Makefile
··· 1 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: 4 - @mkdir -p $(obj)/policy/ 5 - @echo Creating an empty policy/profile.conf 6 - @touch $@ 3 + targets += builtin-policy.h 4 + define do_policy 5 + echo "static char tomoyo_builtin_$(1)[] __initdata ="; \ 6 + $(objtree)/scripts/basic/bin2c <$(firstword $(wildcard $(obj)/policy/$(1).conf $(srctree)/$(src)/policy/$(1).conf.default) /dev/null); \ 7 + echo ";" 8 + endef 9 + quiet_cmd_policy = POLICY $@ 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)) >$@ 7 11 8 - $(obj)/policy/exception_policy.conf: 9 - @mkdir -p $(obj)/policy/ 10 - @echo Creating a default policy/exception_policy.conf 11 - @echo initialize_domain /sbin/modprobe from any >> $@ 12 - @echo initialize_domain /sbin/hotplug from any >> $@ 13 - 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 $@ 12 + $(obj)/builtin-policy.h: $(wildcard $(obj)/policy/*.conf $(src)/policy/*.conf.default) FORCE 13 + $(call if_changed,policy) 47 14 48 15 $(obj)/common.o: $(obj)/builtin-policy.h
+2
security/tomoyo/policy/exception_policy.conf.default
··· 1 + initialize_domain /sbin/modprobe from any 2 + initialize_domain /sbin/hotplug from any
-2
security/yama/Kconfig
··· 1 1 config SECURITY_YAMA 2 2 bool "Yama support" 3 3 depends on SECURITY 4 - select SECURITYFS 5 - select SECURITY_PATH 6 4 default n 7 5 help 8 6 This selects Yama, which extends DAC support with additional
+5 -8
security/yama/yama_lsm.c
··· 379 379 static int yama_dointvec_minmax(struct ctl_table *table, int write, 380 380 void __user *buffer, size_t *lenp, loff_t *ppos) 381 381 { 382 - int rc; 382 + struct ctl_table table_copy; 383 383 384 384 if (write && !capable(CAP_SYS_PTRACE)) 385 385 return -EPERM; 386 386 387 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos); 388 - if (rc) 389 - return rc; 390 - 391 387 /* Lock the max value if it ever gets set. */ 392 - if (write && *(int *)table->data == *(int *)table->extra2) 393 - table->extra1 = table->extra2; 388 + table_copy = *table; 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 395 static int zero;