PM / devfreq: Fix incorrect type issue.
Subsystems (7)
PATCH 30/319 PM / devfreq: Fix incorrect type issue.
From: Xiaolong Ye <[email protected]>
commit 5f25f066f75a67835abb5e400471a27abd09395b upstream
time_in_state in struct devfreq is defined as unsigned long, so devm_kzalloc should use sizeof(unsigned long) as argument instead of sizeof(unsigned int), otherwise it will cause unexpected result in 64bit system.
--- drivers/devfreq/devfreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/devfreq/devfreq.c +1 -1
@@ -472,7 +472,7 @@ struct devfreq *devfreq_add_device(struct device *dev, devfreq->profile->max_state * devfreq->profile->max_state, GFP_KERNEL); - devfreq->time_in_state =devm_kzalloc (dev,sizeof (unsigned int ) * + devfreq->time_in_state =devm_kzalloc (dev,sizeof (unsigned long ) * devfreq->profile->max_state,GFP_KERNEL ); devfreq->last_stat_updated = jiffies;
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 31/319 ppp: defer netns reference release for ppp channel
From: WANG Cong <[email protected]>
commit 205e1e255c479f3fd77446415706463b282f94e4 upstream
Matt reported that we have a NULL pointer dereference in ppp_pernet() from ppp_connect_channel(), i.e. pch->chan_net is NULL.
This is due to that a parallel ppp_unregister_channel() could happen while we are in ppp_connect_channel(), during which pch->chan_net set to NULL. Since we need a reference to net per channel, it makes sense to sync the refcnt with the life time of the channel, therefore we should release this reference when we destroy it.
--- drivers/net/ppp/ppp_generic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ppp/ppp_generic.c +3 -2
@@ -2317,8 +2317,6 @@ ppp_unregister_channel(struct ppp_channel *chan)spin_lock_bh (&pn->all_channels_lock);list_del (&pch->list);spin_unlock_bh (&pn->all_channels_lock); -put_net (pch->chan_net); - pch->chan_net =NULL ; pch->file.dead =1 ;wake_up_interruptible (&pch->file.rwait);
@@ -2925,6 +2923,9 @@ ppp_disconnect_channel(struct channel *pch)*/ static void ppp_destroy_channel (struct channel *pch) { +put_net (pch->chan_net); + pch->chan_net =NULL ; +atomic_dec (&channel_count);if (!pch->file.dead) {
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 32/319 x86/mm/xen: Suppress hugetlbfs in PV guests
In reply to Willy TarreauFrom: Jan Beulich <[email protected]>
commit 103f6112f253017d7062cd74d17f4a514ed4485c upstream.
Huge pages are not normally available to PV guests. Not suppressing hugetlbfs use results in an endless loop of page faults when user mode code tries to access a hugetlbfs mapped area (since the hypervisor denies such PTEs to be created, but error indications can't be propagated out of xen_set_pte_at(), just like for various of its siblings), and - once killed in an oops like this:
kernel BUG at .../fs/hugetlbfs/inode.c:428!
invalid opcode: 0000 [#1] SMP
...
RIP: e030:[<ffffffff811c333b>] [<ffffffff811c333b>] remove_inode_hugepages+0x25b/0x320 ... Call Trace: [<ffffffff811c3415>] hugetlbfs_evict_inode+0x15/0x40 [<ffffffff81167b3d>] evict+0xbd/0x1b0 [<ffffffff8116514a>] __dentry_kill+0x19a/0x1f0 [<ffffffff81165b0e>] dput+0x1fe/0x220 [<ffffffff81150535>] __fput+0x155/0x200 [<ffffffff81079fc0>] task_work_run+0x60/0xa0 [<ffffffff81063510>] do_exit+0x160/0x400 [<ffffffff810637eb>] do_group_exit+0x3b/0xa0 [<ffffffff8106e8bd>] get_signal+0x1ed/0x470 [<ffffffff8100f854>] do_signal+0x14/0x110 [<ffffffff810030e9>] prepare_exit_to_usermode+0xe9/0xf0 [<ffffffff814178a5>] retint_user+0x8/0x13
This is CVE-2016-3961 / XSA-174.
--- arch/x86/include/asm/hugetlb.h | 1 + 1 file changed, 1 insertion(+)
arch/x86/include/asm/hugetlb.h +1 -0
@@ -4,6 +4,7 @@#include <asm/page.h> #include <asm-generic/hugetlb.h> +#define hugepages_supported () cpu_has_pse static inline int is_hugepage_only_range(struct mm_struct *mm, unsigned long addr,
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 33/319 xen: Add RING_COPY_REQUEST()
In reply to Willy TarreauFrom: David Vrabel <[email protected]>
commit 454d5d882c7e412b840e3c99010fe81a9862f6fb upstream.
Using RING_GET_REQUEST() on a shared ring is easy to use incorrectly (i.e., by not considering that the other end may alter the data in the shared ring while it is being inspected). Safe usage of a request generally requires taking a local copy.
Provide a RING_COPY_REQUEST() macro to use instead of RING_GET_REQUEST() and an open-coded memcpy(). This takes care of ensuring that the copy is done correctly regardless of any possible compiler optimizations.
Use a volatile source to prevent the compiler from reordering or omitting the copy.
This is part of XSA155.
--- include/xen/interface/io/ring.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/xen/interface/io/ring.h +14 -0
@@ -181,6 +181,20 @@ struct __name##_back_ring { \#define RING_GET_REQUEST (_r, _idx) \ (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].req)) +/* +* Get a local copy of a request. +* +* Use this in preference to RING_GET_REQUEST() so all processing is +* done on a local copy that cannot be modified by the other end. +* +* Note that https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58145 may cause this +* to be ineffective where _req is a struct which consists of only bitfields. +*/ +#define RING_COPY_REQUEST (_r, _idx, _req) do { \ +/* Use volatile to force the copy into _req. */ \ + *(_req) = *(volatile typeof (_req ))RING_GET_REQUEST (_r, _idx); \ +} while (0) +#define RING_GET_RESPONSE (_r, _idx) \ (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].rsp))
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 34/319 xen-netback: don't use last request to determine minimum Tx credit
In reply to Willy TarreauFrom: David Vrabel <[email protected]>
commit 0f589967a73f1f30ab4ac4dd9ce0bb399b4d6357 upstream.
The last from guest transmitted request gives no indication about the minimum amount of credit that the guest might need to send a packet since the last packet might have been a small one.
Instead allow for the worst case 128 KiB packet.
This is part of XSA155.
--- drivers/net/xen-netback/netback.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/xen-netback/netback.c +1 -3
@@ -928,9 +928,7 @@ static void tx_add_credit(struct xenvif *vif)* Allow a burst big enough to transmit a jumbo packet of up to 128kB. * Otherwise the interface can seize up due to insufficient credit. */ - max_burst =RING_GET_REQUEST (&vif->tx, vif->tx.req_cons)->size; - max_burst =min (max_burst,131072UL ); - max_burst =max (max_burst, vif->credit_bytes); + max_burst =max (131072UL , vif->credit_bytes);/* Take care that adding a new chunk of credit doesn't wrap to zero. */ max_credit = vif->remaining_credit + vif->credit_bytes;
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 35/319 xen-netback: use RING_COPY_REQUEST() throughout
In reply to Willy TarreauFrom: David Vrabel <[email protected]>
commit 68a33bfd8403e4e22847165d149823a2e0e67c9c upstream.
Instead of open-coding memcpy()s and directly accessing Tx and Rx requests, use the new RING_COPY_REQUEST() that ensures the local copy is correct.
This is more than is strictly necessary for guest Rx requests since only the id and gref fields are used and it is harmless if the frontend modifies these.
This is part of XSA155.
--- drivers/net/xen-netback/netback.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-)
drivers/net/xen-netback/netback.c +14 -16
@@ -454,17 +454,17 @@ static struct netbk_rx_meta *get_next_rx_buffer(struct xenvif *vif, struct netrx_pending_operations *npo) {struct netbk_rx_meta *meta; -struct xen_netif_rx_request *req; +struct xen_netif_rx_request req; - req =RING_GET_REQUEST (&vif->rx, vif->rx.req_cons++); +RING_COPY_REQUEST (&vif->rx, vif->rx.req_cons++, &req); meta = npo->meta + npo->meta_prod++; meta->gso_size =0 ; meta->size =0 ; - meta->id = req->id; + meta->id = req.id; npo->copy_off =0 ; - npo->copy_gref = req->gref; + npo->copy_gref = req.gref;return meta; }
@@ -582,7 +582,7 @@ static int netbk_gop_skb(struct sk_buff *skb,struct xenvif *vif =netdev_priv (skb->dev);int nr_frags =skb_shinfo (skb)->nr_frags;int i; -struct xen_netif_rx_request *req; +struct xen_netif_rx_request req;struct netbk_rx_meta *meta;unsigned char *data;int head =1 ;
@@ -592,14 +592,14 @@ static int netbk_gop_skb(struct sk_buff *skb,/* Set up a GSO prefix descriptor, if necessary */ if (skb_shinfo (skb)->gso_size && vif->gso_prefix) { - req =RING_GET_REQUEST (&vif->rx, vif->rx.req_cons++); +RING_COPY_REQUEST (&vif->rx, vif->rx.req_cons++, &req); meta = npo->meta + npo->meta_prod++; meta->gso_size =skb_shinfo (skb)->gso_size; meta->size =0 ; - meta->id = req->id; + meta->id = req.id; } - req =RING_GET_REQUEST (&vif->rx, vif->rx.req_cons++); +RING_COPY_REQUEST (&vif->rx, vif->rx.req_cons++, &req); meta = npo->meta + npo->meta_prod++;if (!vif->gso_prefix)
@@ -608,9 +608,9 @@ static int netbk_gop_skb(struct sk_buff *skb, meta->gso_size =0 ; meta->size =0 ; - meta->id = req->id; + meta->id = req.id; npo->copy_off =0 ; - npo->copy_gref = req->gref; + npo->copy_gref = req.gref; data = skb->data;while (data <skb_tail_pointer (skb)) {
@@ -954,7 +954,7 @@ static void netbk_tx_err(struct xenvif *vif,make_tx_response (vif, txp,XEN_NETIF_RSP_ERROR );if (cons == end)break ; - txp =RING_GET_REQUEST (&vif->tx, cons++); +RING_COPY_REQUEST (&vif->tx, cons++, txp); }while (1 ); vif->tx.req_cons = cons;xen_netbk_check_rx_xenvif (vif);
@@ -1021,8 +1021,7 @@ static int netbk_count_requests(struct xenvif *vif,if (drop_err) txp = &dropped_tx; -memcpy (txp,RING_GET_REQUEST (&vif->tx, cons + slots), -sizeof (*txp)); +RING_COPY_REQUEST (&vif->tx, cons + slots, txp);/* If the guest submitted a frame >= 64 KiB then * first->size overflowed and following slots will
@@ -1310,8 +1309,7 @@ static int xen_netbk_get_extras(struct xenvif *vif,return -EBADR ; } -memcpy (&extra,RING_GET_REQUEST (&vif->tx, cons), -sizeof (extra)); +RING_COPY_REQUEST (&vif->tx, cons, &extra);if (unlikely (!extra.type || extra.type >=XEN_NETIF_EXTRA_TYPE_MAX )) { vif->tx.req_cons = ++cons;
@@ -1501,7 +1499,7 @@ static unsigned xen_netbk_tx_build_gops(struct xen_netbk *netbk) idx = vif->tx.req_cons;rmb ();/* Ensure that we see the request before we copy it. */ -memcpy (&txreq,RING_GET_REQUEST (&vif->tx, idx),sizeof (txreq)); +RING_COPY_REQUEST (&vif->tx, idx, &txreq);/* Credit-based scheduling. */ if (txreq.size > vif->remaining_credit &&
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 36/319 xen-blkback: only read request operation from shared ring once
In reply to Willy TarreauFrom: Roger Pau Monn� <[email protected]>
commit 1f13d75ccb806260079e0679d55d9253e370ec8a upstream.
A compiler may load a switch statement value multiple times, which could be bad when the value is in memory shared with the frontend.
When converting a non-native request to a native one, ensure that src->operation is only loaded once by using READ_ONCE().
This is part of XSA155.
--- drivers/block/xen-blkback/common.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/block/xen-blkback/common.h +4 -4
@@ -269,8 +269,8 @@ static inline void blkif_get_x86_32_req(struct blkif_request *dst, struct blkif_x86_32_request *src) {int i, n =BLKIF_MAX_SEGMENTS_PER_REQUEST ; - dst->operation = src->operation; -switch (src->operation) { + dst->operation =READ_ONCE (src->operation); +switch (dst->operation) {case BLKIF_OP_READ :case BLKIF_OP_WRITE :case BLKIF_OP_WRITE_BARRIER :
@@ -305,8 +305,8 @@ static inline void blkif_get_x86_64_req(struct blkif_request *dst, struct blkif_x86_64_request *src) {int i, n =BLKIF_MAX_SEGMENTS_PER_REQUEST ; - dst->operation = src->operation; -switch (src->operation) { + dst->operation =READ_ONCE (src->operation); +switch (dst->operation) {case BLKIF_OP_READ :case BLKIF_OP_WRITE :case BLKIF_OP_WRITE_BARRIER :
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 37/319 xen/pciback: Save xen_pci_op commands before processing it
In reply to Willy TarreauFrom: Konrad Rzeszutek Wilk <[email protected]>
commit 8135cf8b092723dbfcc611fe6fdcb3a36c9951c5 upstream.
Double fetch vulnerabilities that happen when a variable is fetched twice from shared memory but a security check is only performed the first time.
The xen_pcibk_do_op function performs a switch statements on the op->cmd value which is stored in shared memory. Interestingly this can result in a double fetch vulnerability depending on the performed compiler optimization.
This patch fixes it by saving the xen_pci_op command before processing it. We also use 'barrier' to make sure that the compiler does not perform any optimization.
This is part of XSA155.
--- drivers/xen/xen-pciback/pciback.h | 1 + drivers/xen/xen-pciback/pciback_ops.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)
drivers/xen/xen-pciback/pciback.h +1 -0
@@ -37,6 +37,7 @@ struct xen_pcibk_device {struct xen_pci_sharedinfo *sh_info;unsigned long flags;struct work_struct op_work; +struct xen_pci_op op; };struct xen_pcibk_dev_data {
drivers/xen/xen-pciback/pciback_ops.c +14 -1
@@ -295,9 +295,11 @@ void xen_pcibk_do_op(struct work_struct *data) container_of(data, struct xen_pcibk_device, op_work);struct pci_dev *dev;struct xen_pcibk_dev_data *dev_data =NULL ; -struct xen_pci_op *op = &pdev->sh_info->op; +struct xen_pci_op *op = &pdev->op;int test_intx =0 ; + *op = pdev->sh_info->op; +barrier (); dev =xen_pcibk_get_pci_dev (pdev, op->domain, op->bus, op->devfn);if (dev ==NULL )
@@ -339,6 +341,17 @@ void xen_pcibk_do_op(struct work_struct *data)if ((dev_data->enable_intx != test_intx))xen_pcibk_control_isr (dev,0 /* no reset */ ); } + pdev->sh_info->op.err = op->err; + pdev->sh_info->op.value = op->value; +#ifdef CONFIG_PCI_MSI +if (op->cmd == XEN_PCI_OP_enable_msix && op->err ==0 ) { +unsigned int i; + +for (i =0 ; i < op->value; i++) + pdev->sh_info->op.msix_entries[i].vector = + op->msix_entries[i].vector; + } +#endif /* Tell the driver domain that we're done. */ wmb ();clear_bit (_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags);
Signature · 1 line
2.8.0.rc2.1.gbe9624a
Re: [PATCH 3.10 037/319] xen/pciback: Save xen_pci_op commands before processing it
Quoted 3 lines · Willy Tarreau
From: Konrad Rzeszutek Wilk <[email protected]>
commit
8135cf8b092723dbfcc611fe6fdcb3a36c9951c5upstream.
You also need:
commit d159457b84395927b5a52adb72f748dd089ad5e5
Author: Konrad Rzeszutek Wilk <[email protected]> Date: Thu Feb 11 16:10:24 2016 -0500
xen/pciback: Save the number of MSI-X entries to be copied later.
Commit 8135cf8b092723dbfcc611fe6fdcb3a36c9951c5 (xen/pciback: Save xen_pci_op commands before processing it) broke enabling MSI-X because it would never copy the resulting vectors into the response. The number of vectors requested was being overwritten by the return value (typically zero for success).
Quoted 77 lines
Double fetch vulnerabilities that happen when a variable is fetched twice from shared memory but a security check is only performed the first time.
The
xen_pcibk_do_opfunction performs a switch statements on theop->cmdvalue which is stored in shared memory. Interestingly this can result in a double fetch vulnerability depending on the performed compiler optimization.This patch fixes it by saving the
xen_pci_opcommand before processing it. We also use 'barrier' to make sure that the compiler does not perform any optimization.This is part of XSA155.
Reviewed-by Konrad Rzeszutek Wilk <[email protected]>Signed-off-by Jan Beulich <[email protected]>Signed-off-by David Vrabel <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>Cc "Jan Beulich" <[email protected]>Signed-off-by Willy Tarreau <[email protected]>--- drivers/xen/xen-pciback/pciback.h | 1 + drivers/xen/xen-pciback/pciback_ops.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)drivers/xen/xen-pciback/pciback.h +1
-0@@ -37,6 +37,7 @@ struct xen_pcibk_device {struct xen_pci_sharedinfo *sh_info;unsigned long flags;struct work_struct op_work; +struct xen_pci_op op; };struct xen_pcibk_dev_data {drivers/xen/xen-pciback/pciback_ops.c +14
-1@@ -295,9 +295,11 @@ void xen_pcibk_do_op(struct work_struct *data) container_of(data, struct xen_pcibk_device, op_work);struct pci_dev *dev;struct xen_pcibk_dev_data *dev_data =NULL ; -struct xen_pci_op *op = &pdev->sh_info->op; +struct xen_pci_op *op = &pdev->op;int test_intx =0 ; + *op = pdev->sh_info->op; +barrier (); dev =xen_pcibk_get_pci_dev (pdev, op->domain, op->bus, op->devfn);if (dev ==NULL )@@ -339,6 +341,17 @@ void xen_pcibk_do_op(struct work_struct *data)if ((dev_data->enable_intx != test_intx))xen_pcibk_control_isr (dev,0 /* no reset */ ); } + pdev->sh_info->op.err = op->err; + pdev->sh_info->op.value = op->value; +#ifdef CONFIG_PCI_MSI +if (op->cmd == XEN_PCI_OP_enable_msix && op->err ==0 ) { +unsigned int i; + +for (i =0 ; i < op->value; i++) + pdev->sh_info->op.msix_entries[i].vector = + op->msix_entries[i].vector; + } +#endif /* Tell the driver domain that we're done. */ wmb ();clear_bit (_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags);Signature · 1 line
2.8.0.rc2.1.gbe9624a
Re: [PATCH 3.10 037/319] xen/pciback: Save xen_pci_op commands before processing it
Quoted 11 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Willy Tarreau
From: Konrad Rzeszutek Wilk <[email protected]>
commit
8135cf8b092723dbfcc611fe6fdcb3a36c9951c5upstream.You also need:
commit
d159457b84395927b5a52adb72f748dd089ad5e5Author: Konrad Rzeszutek Wilk <[email protected]> Date: Thu Feb 11 16:10:24 2016 -0500
Quoted 7 lines
xen/pciback: Save the number of MSI-X entries to be copied later.
Commit
8135cf8b092723dbfcc611fe6fdcb3a36c9951c5(xen/pciback: Savexen_pci_opcommands before processing it) broke enabling MSI-X because it would never copy the resulting vectors into the response. The number of vectors requested was being overwritten by the return value (typically zero for success).
Now added as well, thanks Konrad!
Willy
PATCH 38/319 xen/pciback: Return error on XEN_PCI_OP_enable_msi when device has MSI or MSI-X enabled
In reply to Willy TarreauFrom: Konrad Rzeszutek Wilk <[email protected]>
commit 56441f3c8e5bd45aab10dd9f8c505dd4bec03b0d upstream.
The guest sequence of:
a) XEN_PCI_OP_enable_msi
b) XEN_PCI_OP_enable_msi
c) XEN_PCI_OP_disable_msi
results in hitting an BUG_ON condition in the msi.c code.
The MSI code uses an dev->msi_list to which it adds MSI entries. Under the above conditions an BUG_ON() can be hit. The device passed in the guest MUST have MSI capability.
The a) adds the entry to the dev->msi_list and sets msi_enabled. The b) adds a second entry but adding in to SysFS fails (duplicate entry) and deletes all of the entries from msi_list and returns (with msi_enabled is still set). c) pci_disable_msi passes the msi_enabled checks and hits:
BUG_ON(list_empty(dev_to_msi_list(&dev->dev)));
and blows up.
The patch adds a simple check in the XEN_PCI_OP_enable_msi to guard against that. The check for msix_enabled is not stricly neccessary.
This is part of XSA-157.
--- drivers/xen/xen-pciback/pciback_ops.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/xen/xen-pciback/pciback_ops.c +6 -1
@@ -141,7 +141,12 @@ int xen_pcibk_enable_msi(struct xen_pcibk_device *pdev,if (unlikely (verbose_request)) printk(KERN_DEBUG DRV_NAME ": %s: enable MSI\n", pci_name(dev)); - status =pci_enable_msi (dev); +if (dev->msi_enabled) + status = -EALREADY ; +else if (dev->msix_enabled) + status = -ENXIO ; +else + status =pci_enable_msi (dev);if (status) { pr_warn_ratelimited(DRV_NAME ": %s: error enabling MSI for guest %u: err %d\n",
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 39/319 xen/pciback: Return error on XEN_PCI_OP_enable_msix when device has MSI or MSI-X enabled
In reply to Willy TarreauFrom: Konrad Rzeszutek Wilk <[email protected]>
commit 5e0ce1455c09dd61d029b8ad45d82e1ac0b6c4c9 upstream.
The guest sequence of:
a) XEN_PCI_OP_enable_msix
b) XEN_PCI_OP_enable_msix
results in hitting an NULL pointer due to using freed pointers.
The device passed in the guest MUST have MSI-X capability.
The a) constructs and SysFS representation of MSI and MSI groups. The b) adds a second set of them but adding in to SysFS fails (duplicate entry). 'populate_msi_sysfs' frees the newly allocated msi_irq_groups (note that in a) pdev->msi_irq_groups is still set) and also free's ALL of the MSI-X entries of the device (the ones allocated in step a) and b)).
The unwind code: 'free_msi_irqs' deletes all the entries and tries to delete the pdev->msi_irq_groups (which hasn't been set to NULL). However the pointers in the SysFS are already freed and we hit an NULL pointer further on when 'strlen' is attempted on a freed pointer.
The patch adds a simple check in the XEN_PCI_OP_enable_msix to guard against that. The check for msi_enabled is not stricly neccessary.
This is part of XSA-157
--- drivers/xen/xen-pciback/pciback_ops.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/xen/xen-pciback/pciback_ops.c +7 -0
@@ -203,9 +203,16 @@ int xen_pcibk_enable_msix(struct xen_pcibk_device *pdev,if (unlikely (verbose_request)) printk(KERN_DEBUG DRV_NAME ": %s: enable MSI-X\n",pci_name (dev)); +if (op->value >SH_INFO_MAX_VEC )return -EINVAL ; +if (dev->msix_enabled) +return -EALREADY ; + +if (dev->msi_enabled) +return -ENXIO ; + entries =kmalloc (op->value *sizeof (*entries),GFP_KERNEL );if (entries ==NULL )return -ENOMEM ;
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 40/319 xen/pciback: Do not install an IRQ handler for MSI interrupts.
In reply to Willy TarreauFrom: Konrad Rzeszutek Wilk <[email protected]>
commit a396f3a210c3a61e94d6b87ec05a75d0be2a60d0 upstream.
Otherwise an guest can subvert the generic MSI code to trigger an BUG_ON condition during MSI interrupt freeing:
for (i = 0; i < entry->nvec_used; i++)
BUG_ON(irq_has_action(entry->irq + i));
Xen PCI backed installs an IRQ handler (request_irq) for the dev->irq whenever the guest writes PCI_COMMAND_MEMORY (or PCI_COMMAND_IO) to the PCI_COMMAND register. This is done in case the device has legacy interrupts the GSI line is shared by the backend devices.
To subvert the backend the guest needs to make the backend to change the dev->irq from the GSI to the MSI interrupt line, make the backend allocate an interrupt handler, and then command the backend to free the MSI interrupt and hit the BUG_ON.
Since the backend only calls 'request_irq' when the guest writes to the PCI_COMMAND register the guest needs to call XEN_PCI_OP_enable_msi before any other operation. This will cause the generic MSI code to setup an MSI entry and populate dev->irq with the new PIRQ value.
Then the guest can write to PCI_COMMAND PCI_COMMAND_MEMORY and cause the backend to setup an IRQ handler for dev->irq (which instead of the GSI value has the MSI pirq). See 'xen_pcibk_control_isr'.
Then the guest disables the MSI: XEN_PCI_OP_disable_msi which ends up triggering the BUG_ON condition in 'free_msi_irqs' as there is an IRQ handler for the entry->irq (dev->irq).
Note that this cannot be done using MSI-X as the generic code does not over-write dev->irq with the MSI-X PIRQ values.
The patch inhibits setting up the IRQ handler if MSI or MSI-X (for symmetry reasons) code had been called successfully.
P.S.
Xen PCIBack when it sets up the device for the guest consumption ends up writting 0 to the PCI_COMMAND (see xen_pcibk_reset_device). XSA-120 addendum patch removed that - however when upstreaming said addendum we found that it caused issues with qemu upstream. That has now been fixed in qemu upstream.
This is part of XSA-157
--- drivers/xen/xen-pciback/pciback_ops.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/xen/xen-pciback/pciback_ops.c +7 -0
@@ -67,6 +67,13 @@ static void xen_pcibk_control_isr(struct pci_dev *dev, int reset) enable ? "enable" : "disable");if (enable) { +/* +* The MSI or MSI-X should not have an IRQ handler. Otherwise +* if the guest terminates we BUG_ON in free_msi_irqs. +*/ +if (dev->msi_enabled || dev->msix_enabled) + goto out; + rc =request_irq (dev_data->irq, xen_pcibk_guest_interrupt,IRQF_SHARED , dev_data->irq_name, dev);
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 41/319 xen/pciback: For XEN_PCI_OP_disable_msi[|x] only disable if device has MSI(X) enabled.
In reply to Willy TarreauFrom: Konrad Rzeszutek Wilk <[email protected]>
commit 7cfb905b9638982862f0331b36ccaaca5d383b49 upstream.
Otherwise just continue on, returning the same values as previously (return of 0, and op->result has the PIRQ value).
This does not change the behavior of XEN_PCI_OP_disable_msi[|x].
The pci_disable_msi or pci_disable_msix have the checks for msi_enabled or msix_enabled so they will error out immediately.
However the guest can still call these operations and cause us to disable the 'ack_intr'. That means the backend IRQ handler for the legacy interrupt will not respond to interrupts anymore.
This will lead to (if the device is causing an interrupt storm) for the Linux generic code to disable the interrupt line.
Naturally this will only happen if the device in question is plugged in on the motherboard on shared level interrupt GSI.
This is part of XSA-157
--- drivers/xen/xen-pciback/pciback_ops.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-)
drivers/xen/xen-pciback/pciback_ops.c +20 -13
@@ -182,20 +182,23 @@ staticint xen_pcibk_disable_msi (struct xen_pcibk_device *pdev,struct pci_dev *dev,struct xen_pci_op *op) { -struct xen_pcibk_dev_data *dev_data; -if (unlikely (verbose_request)) printk(KERN_DEBUG DRV_NAME ": %s: disable MSI\n",pci_name (dev)); -pci_disable_msi (dev); +if (dev->msi_enabled) { +struct xen_pcibk_dev_data *dev_data; + +pci_disable_msi (dev); + + dev_data =pci_get_drvdata (dev); +if (dev_data) + dev_data->ack_intr =1 ; + } op->value = dev->irq ?xen_pirq_from_irq (dev->irq) :0 ;if (unlikely (verbose_request)) printk(KERN_DEBUG DRV_NAME ": %s: MSI: %d\n", pci_name(dev), op->value); - dev_data =pci_get_drvdata (dev); -if (dev_data) - dev_data->ack_intr =1 ;return 0 ; }
@@ -261,23 +264,27 @@ staticint xen_pcibk_disable_msix (struct xen_pcibk_device *pdev,struct pci_dev *dev,struct xen_pci_op *op) { -struct xen_pcibk_dev_data *dev_data;if (unlikely (verbose_request)) printk(KERN_DEBUG DRV_NAME ": %s: disable MSI-X\n",pci_name (dev)); -pci_disable_msix (dev); +if (dev->msix_enabled) { +struct xen_pcibk_dev_data *dev_data; + +pci_disable_msix (dev); + + dev_data =pci_get_drvdata (dev); +if (dev_data) + dev_data->ack_intr =1 ; + }/* * SR-IOV devices (which don't have any legacy IRQ) have * an undefined IRQ value of zero. */ op->value = dev->irq ?xen_pirq_from_irq (dev->irq) :0 ;if (unlikely (verbose_request)) - printk(KERN_DEBUG DRV_NAME ": %s: MSI-X: %d\n", pci_name(dev), - op->value); - dev_data =pci_get_drvdata (dev); -if (dev_data) - dev_data->ack_intr =1 ; + printk(KERN_DEBUG DRV_NAME ": %s: MSI-X: %d\n", +pci_name (dev), op->value);return 0 ; }#endif
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 42/319 xen/pciback: Don't allow MSI-X ops if PCI_COMMAND_MEMORY is not set.
In reply to Willy TarreauFrom: Konrad Rzeszutek Wilk <[email protected]>
commit 408fb0e5aa7fda0059db282ff58c3b2a4278baa0 upstream.
commit f598282f51 ("PCI: Fix the NIU MSI-X problem in a better way") teaches us that dealing with MSI-X can be troublesome.
Further checks in the MSI-X architecture shows that if the PCI_COMMAND_MEMORY bit is turned of in the PCI_COMMAND we may not be able to access the BAR (since they are memory regions).
Since the MSI-X tables are located in there.. that can lead to us causing PCIe errors. Inhibit us performing any operation on the MSI-X unless the MEMORY bit is set.
Note that Xen hypervisor with:
"x86/MSI-X: access MSI-X table only after having enabled MSI-X" will return:xen_pciback: 0000:0a:00.1: error -6 enabling MSI-X for guest 3!
When the generic MSI code tries to setup the PIRQ without MEMORY bit set. Which means with later versions of Xen (4.6) this patch is not neccessary.
This is part of XSA-157
--- drivers/xen/xen-pciback/pciback_ops.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/xen/xen-pciback/pciback_ops.c +7 -1
@@ -209,6 +209,7 @@ int xen_pcibk_enable_msix(struct xen_pcibk_device *pdev,struct xen_pcibk_dev_data *dev_data;int i, result;struct msix_entry *entries; +u16 cmd;if (unlikely (verbose_request)) printk(KERN_DEBUG DRV_NAME ": %s: enable MSI-X\n",
@@ -220,7 +221,12 @@ int xen_pcibk_enable_msix(struct xen_pcibk_device *pdev,if (dev->msix_enabled)return -EALREADY ; -if (dev->msi_enabled) +/* +* PCI_COMMAND_MEMORY must be enabled, otherwise we may not be able +* to access the BARs where the MSI-X entries reside. +*/ +pci_read_config_word (dev,PCI_COMMAND , &cmd); +if (dev->msi_enabled || !(cmd &PCI_COMMAND_MEMORY ))return -ENXIO ; entries =kmalloc (op->value *sizeof (*entries),GFP_KERNEL );
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 43/319 xen-pciback: Add name prefix to global 'permissive' variable
In reply to Willy TarreauFrom: Ben Hutchings <[email protected]>
commit 8014bcc86ef112eab9ee1db312dba4e6b608cf89 upstream.
The variable for the 'permissive' module parameter used to be static but was recently changed to be extern. This puts it in the kernel global namespace if the driver is built-in, so its name should begin with a prefix identifying the driver.
--- drivers/xen/xen-pciback/conf_space.c | 6 +++--- drivers/xen/xen-pciback/conf_space.h | 2 +- drivers/xen/xen-pciback/conf_space_header.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/xen/xen-pciback/conf_space.c +3 -3
@@ -16,8 +16,8 @@#include "conf_space.h" #include "conf_space_quirks.h" -bool permissive; -module_param (permissive, bool,0644 ); +bool xen_pcibk_permissive; +module_param_named (permissive, xen_pcibk_permissive, bool,0644 );/* This is where xen_pcibk_read_config_byte, xen_pcibk_read_config_word, * xen_pcibk_write_config_word, and xen_pcibk_write_config_byte are created. */
@@ -260,7 +260,7 @@ int xen_pcibk_config_write(struct pci_dev *dev, int offset, int size, u32 value)* This means that some fields may still be read-only because * they have entries in the config_field list that intercept * the write and do nothing. */ -if (dev_data->permissive || permissive) { +if (dev_data->permissive || xen_pcibk_permissive) {switch (size) {case 1 : err = pci_write_config_byte(dev, offset,
drivers/xen/xen-pciback/conf_space.h +1 -1
@@ -64,7 +64,7 @@ struct config_field_entry {void *data; }; -extern bool permissive; +extern bool xen_pcibk_permissive;#define OFFSET (cfg_entry) ((cfg_entry)->base_offset+(cfg_entry)->field->offset)
drivers/xen/xen-pciback/conf_space_header.c +1 -1
@@ -105,7 +105,7 @@ static int command_write(struct pci_dev *dev, int offset, u16 value, void *data) cmd->val = value; -if (!permissive && (!dev_data || !dev_data->permissive)) +if (!xen_pcibk_permissive && (!dev_data || !dev_data->permissive))return 0 ;/* Only allow the guest to control certain bits. */
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 44/319 x86/xen: fix upper bound of pmd loop in xen_cleanhighmap()
In reply to Willy TarreauFrom: Juergen Gross <[email protected]>
commit 1cf38741308c64d08553602b3374fb39224eeb5a upstream.
xen_cleanhighmap() is operating on level2_kernel_pgt only. The upper bound of the loop setting non-kernel-image entries to zero should not exceed the size of level2_kernel_pgt.
--- arch/x86/xen/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/xen/mmu.c +1 -1
@@ -1187,7 +1187,7 @@ static void __init xen_cleanhighmap(unsigned long vaddr,/* NOTE: The loop is more greedy than the cleanup_highmap variant. * We include the PMD passed in on _both_ boundaries. */ -for (; vaddr <= vaddr_end && (pmd < (level2_kernel_pgt +PAGE_SIZE )); +for (; vaddr <= vaddr_end && (pmd < (level2_kernel_pgt +PTRS_PER_PMD )); pmd++, vaddr +=PMD_SIZE ) {if (pmd_none (*pmd))continue ;
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 45/319 x86/traps: Ignore high word of regs->cs in early_idt_handler_common
In reply to Willy TarreauFrom: Andy Lutomirski <[email protected]>
This is a backport of:
commit fc0e81b2bea0ebceb71889b61d2240856141c9ee upstream
On the 80486 DX, it seems that some exceptions may leave garbage in the high bits of CS. This causes sporadic failures in which early_fixup_exception() refuses to fix up an exception.
As far as I can tell, this has been buggy for a long time, but the problem seems to have been exacerbated by commits:
1e02ce4cccdc ("x86: Store a per-cpu shadow copy of CR4") e1bfc11c5a6f ("x86/init: Fix cr4_init_shadow() on CR4-less machines")
This appears to have broken for as long as we've had early exception handling.
[ This backport should apply to kernels from 3.4 - 4.5. ]
--- arch/x86/kernel/head_32.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/head_32.S +1 -1
@@ -586,7 +586,7 @@ early_idt_handler_common: movl %eax,%ds movl %eax,%es - cmpl $(__KERNEL_CS),32(%esp) + cmpw $(__KERNEL_CS),32(%esp) jne 10f leal 28(%esp),%eax # Pointer to %eip
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 46/319 x86/mm: Disable preemption during CR3 read+write
In reply to Willy TarreauFrom: Sebastian Andrzej Siewior <[email protected]>
commit 5cf0791da5c162ebc14b01eb01631cfa7ed4fa6e upstream.
There's a subtle preemption race on UP kernels:
Usually current->mm (and therefore mm->pgd) stays the same during the lifetime of a task so it does not matter if a task gets preempted during the read and write of the CR3.
But then, there is this scenario on x86-UP:
TaskA is in do_exit() and exit_mm() sets current->mm = NULL followed by:
-> mmput()
-> exit_mmap()
-> tlb_finish_mmu()
-> tlb_flush_mmu()
-> tlb_flush_mmu_tlbonly()
-> tlb_flush()
-> flush_tlb_mm_range()
-> __flush_tlb_up()
-> __flush_tlb()
-> __native_flush_tlb()
At this point current->mm is NULL but current->active_mm still points to the "old" mm.
Let's preempt taskA _after_ native_read_cr3() by taskB. TaskB has its own mm so CR3 has changed.
Now preempt back to taskA. TaskA has no ->mm set so it borrows taskB's mm and so CR3 remains unchanged. Once taskA gets active it continues where it was interrupted and that means it writes its old CR3 value back. Everything is fine because userland won't need its memory anymore.
Now the fun part:
Let's preempt taskA one more time and get back to taskB. This time switch_mm() won't do a thing because oldmm (->active_mm) is the same as mm (as per context_switch()). So we remain with a bad CR3 / PGD and return to userland.
The next thing that happens is handle_mm_fault() with an address for the execution of its code in userland. handle_mm_fault() realizes that it has a PTE with proper rights so it returns doing nothing. But the CPU looks at the wrong PGD and insists that something is wrong and faults again. And again. And one more time…
This pagefault circle continues until the scheduler gets tired of it and puts another task on the CPU. It gets little difficult if the task is a RT task with a high priority. The system will either freeze or it gets fixed by the software watchdog thread which usually runs at RT-max prio. But waiting for the watchdog will increase the latency of the RT task which is no good.
Fix this by disabling preemption across the critical code section.
--- arch/x86/include/asm/tlbflush.h | 7 +++++++ 1 file changed, 7 insertions(+)
arch/x86/include/asm/tlbflush.h +7 -0
@@ -17,7 +17,14 @@static inline void __native_flush_tlb (void ) { +/* +* If current->mm == NULL then we borrow a mm which may change during a +* task switch and therefore we must not be preempted while we write CR3 +* back: +*/ +preempt_disable ();native_write_cr3 (native_read_cr3 ()); +preempt_enable (); }static inline void __native_flush_tlb_global_irq_disabled (void )
Signature · 7 lines
2.8.0.rc2.1.gbe9624a -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 47/319 x86/apic: Do not init irq remapping if ioapic is disabled
In reply to Willy TarreauFrom: Wanpeng Li <[email protected]>
commit 2e63ad4bd5dd583871e6602f9d398b9322d358d9 upstream.
native_smp_prepare_cpus
-> default_setup_apic_routing
-> enable_IR_x2apic
-> irq_remapping_prepare
-> intel_prepare_irq_remapping
-> intel_setup_irq_remappingSo IR table is setup even if "noapic" boot parameter is added. As a result we crash later when the interrupt affinity is set due to a half initialized remapping infrastructure.
Prevent remap initialization when IOAPIC is disabled.
--- arch/x86/kernel/apic/apic.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/kernel/apic/apic.c +3 -0
@@ -1581,6 +1581,9 @@ void __init enable_IR_x2apic(void)int ret, x2apic_enabled =0 ;int hardware_init_ret; +if (skip_ioapic_setup) +return ; +/* Make sure irq_remap_ops are initialized */ setup_irq_remapping_ops ();
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 48/319 x86/mm/pat, /dev/mem: Remove superfluous error message
In reply to Willy TarreauFrom: Jiri Kosina <[email protected]>
commit 39380b80d72723282f0ea1d1bbf2294eae45013e upstream.
Currently it's possible for broken (or malicious) userspace to flood a kernel log indefinitely with messages a-la
Program dmidecode tried to access /dev/mem between f0000->100000
because range_is_allowed() is case of CONFIG_STRICT_DEVMEM being turned on dumps this information each and every time devmem_is_allowed() fails.
Reportedly userspace that is able to trigger contignuous flow of these messages exists.
It would be possible to rate limit this message, but that'd have a questionable value; the administrator wouldn't get information about all the failing accessess, so then the information would be both superfluous and incomplete at the same time :)
Returning EPERM (which is what is actually happening) is enough indication for userspace what has happened; no need to log this particular error as some sort of special condition.
--- arch/x86/mm/pat.c | 5 +---- drivers/char/mem.c | 6 +----- 2 files changed, 2 insertions(+), 9 deletions(-)
arch/x86/mm/pat.c +1 -4
@@ -505,11 +505,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)return 1 ;while (cursor < to) { -if (!devmem_is_allowed (pfn)) { -printk (KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n" , - current->comm, from, to -1 ); +if (!devmem_is_allowed (pfn))return 0 ; - } cursor +=PAGE_SIZE ; pfn++; }
drivers/char/mem.c +1 -5
@@ -68,12 +68,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)u64 cursor = from;while (cursor < to) { -if (!devmem_is_allowed (pfn)) { -printk (KERN_INFO -"Program %s tried to access /dev/mem between %Lx->%Lx.\n" , - current->comm, from, to); +if (!devmem_is_allowed (pfn))return 0 ; - } cursor +=PAGE_SIZE ; pfn++; }
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 49/319 x86/paravirt: Do not trace _paravirt_ident_*() functions
In reply to Willy TarreauFrom: Steven Rostedt <[email protected]>
commit 15301a570754c7af60335d094dd2d1808b0641a5 upstream.
�ukasz Daniluk reported that on a RHEL kernel that his machine would lock up after enabling function tracer. I asked him to bisect the functions within available_filter_functions, which he did and it came down to three:
_paravirt_nop(), _paravirt_ident_32() and _paravirt_ident_64()
It was found that this is only an issue when noreplace-paravirt is added to the kernel command line.
This means that those functions are most likely called within critical sections of the funtion tracer, and must not be traced.
In newer kenels _paravirt_nop() is defined within gcc asm(), and is no longer an issue. But both _paravirt_ident_{32,64}() causes the following splat when they are traced:
mm/pgtable-generic.c:33: bad pmd ffff8800d2435150(0000000001d00054) mm/pgtable-generic.c:33: bad pmd ffff8800d3624190(0000000001d00070) mm/pgtable-generic.c:33: bad pmd ffff8800d36a5110(0000000001d00054) mm/pgtable-generic.c:33: bad pmd ffff880118eb1450(0000000001d00054) NMI watchdog: BUG: soft lockup - CPU#2 stuck for 22s! [systemd-journal:469]
Modules linked in: e1000e CPU: 2 PID: 469 Comm: systemd-journal Not tainted 4.6.0-rc4-test+ #513 Hardware name: Hewlett-Packard HP Compaq Pro 6300 SFF/339A, BIOS K01 v02.05 05/07/2012 task: ffff880118f740c0 ti: ffff8800d4aec000 task.ti: ffff8800d4aec000 RIP: 0010:[<ffffffff81134148>] [<ffffffff81134148>] queued_spin_lock_slowpath+0x118/0x1a0 RSP: 0018:ffff8800d4aefb90 EFLAGS: 00000246 RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffff88011eb16d40 RDX: ffffffff82485760 RSI: 000000001f288820 RDI: ffffea0000008030 RBP: ffff8800d4aefb90 R08: 00000000000c0000 R09: 0000000000000000 R10: ffffffff821c8e0e R11: 0000000000000000 R12: ffff880000200fb8 R13: 00007f7a4e3f7000 R14: ffffea000303f600 R15: ffff8800d4b562e0 FS: 00007f7a4e3d7840(0000) GS:ffff88011eb00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f7a4e3f7000 CR3: 00000000d3e71000 CR4: 00000000001406e0 Call Trace: _raw_spin_lock+0x27/0x30 handle_pte_fault+0x13db/0x16b0 handle_mm_fault+0x312/0x670 __do_page_fault+0x1b1/0x4e0 do_page_fault+0x22/0x30 page_fault+0x28/0x30 __vfs_read+0x28/0xe0 vfs_read+0x86/0x130 SyS_read+0x46/0xa0 entry_SYSCALL_64_fastpath+0x1e/0xa8 Code: 12 48 c1 ea 0c 83 e8 01 83 e2 30 48 98 48 81 c2 40 6d 01 00 48 03 14 c5 80 6a 5d 82 48 89 0a 8b 41 08 85 c0 75 09 f3 90 8b 41 08 <85> c0 74 f7 4c 8b 09 4d 85 c9 74 08 41 0f 18 09 eb 02 f3 90 8b
--- arch/x86/kernel/paravirt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/paravirt.c +2 -2
@@ -46,12 +46,12 @@ void _paravirt_nop(void) }/* identity function, which can be inlined */ -u32 _paravirt_ident_32 (u32 x) +u32 notrace _paravirt_ident_32(u32 x) {return x; } -u64 _paravirt_ident_64 (u64 x) +u64 notrace _paravirt_ident_64(u64 x) {return x; }
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 50/319 x86/build: Build compressed x86 kernels as PIE
In reply to Willy TarreauFrom: "H.J. Lu" <[email protected]>
commit 6d92bc9d483aa1751755a66fee8fb39dffb088c0 upstream.
The 32-bit x86 assembler in binutils 2.26 will generate R_386_GOT32X relocation to get the symbol address in PIC. When the compressed x86 kernel isn't built as PIC, the linker optimizes R_386_GOT32X relocations to their fixed symbol addresses. However, when the compressed x86 kernel is loaded at a different address, it leads to the following load failure:
Failed to allocate space for phdrs
during the decompression stage.
If the compressed x86 kernel is relocatable at run-time, it should be compiled with -fPIE, instead of -fPIC, if possible and should be built as Position Independent Executable (PIE) so that linker won't optimize R_386_GOT32X relocation to its fixed symbol address.
Older linkers generate R_386_32 relocations against locally defined symbols, _bss, _ebss, _got and _egot, in PIE. It isn't wrong, just less optimal than R_386_RELATIVE. But the x86 kernel fails to properly handle R_386_32 relocations when relocating the kernel. To generate R_386_RELATIVE relocations, we mark _bss, _ebss, _got and _egot as hidden in both 32-bit and 64-bit x86 kernels.
To build a 64-bit compressed x86 kernel as PIE, we need to disable the relocation overflow check to avoid relocation overflow errors. We do this with a new linker command-line option, -z noreloc-overflow, which got added recently:
commit 4c10bbaa0912742322f10d9d5bb630ba4e15dfa7
Author: H.J. Lu <[email protected]>
Date: Tue Mar 15 11:07:06 2016 -0700
Add -z noreloc-overflow option to x86-64 ld
Add -z noreloc-overflow command-line option to the x86-64 ELF linker to disable relocation overflow check. This can be used to avoid relocation overflow check if there will be no dynamic relocation overflow at run-time.
The 64-bit compressed x86 kernel is built as PIE only if the linker supports -z noreloc-overflow. So far 64-bit relocatable compressed x86 kernel boots fine even when it is built as a normal executable.
--- arch/x86/boot/compressed/Makefile | 14 +++++++++++++- arch/x86/boot/compressed/head_32.S | 28 ++++++++++++++++++++++++++++ arch/x86/boot/compressed/head_64.S | 8 ++++++++ 3 files changed, 49 insertions(+), 1 deletion(-)
arch/x86/boot/compressed/Makefile +13 -1
@@ -7,7 +7,7 @@ targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2 -KBUILD_CFLAGS += -fno-strict-aliasing -fPIC +KBUILD_CFLAGS += -fno-strict-aliasing $(call cc-option, -fPIE, -fPIC) KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING cflags-$(CONFIG_X86_32) := -march=i386 cflags-$(CONFIG_X86_64) := -mcmodel=small
@@ -20,6 +20,18 @@ KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ GCOV_PROFILE := n LDFLAGS := -m elf_$(UTS_MACHINE) +ifeq ($(CONFIG_RELOCATABLE),y) +# If kernel is relocatable, build compressed kernel as PIE. +ifeq ($(CONFIG_X86_32),y) +LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker) +else +# To build 64-bit compressed kernel as PIE, we disable relocation +# overflow check to avoid relocation overflow error with a new linker +# command-line option, -z noreloc-overflow. +LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \ + && echo "-z noreloc-overflow -pie --no-dynamic-linker") +endif +endif LDFLAGS_vmlinux := -T hostprogs-y := mkpiggy
arch/x86/boot/compressed/head_32.S +28 -0
@@ -30,6 +30,34 @@ #include <asm/boot.h> #include <asm/asm-offsets.h> +/* + * The 32-bit x86 assembler in binutils 2.26 will generate R_386_GOT32X + * relocation to get the symbol address in PIC. When the compressed x86 + * kernel isn't built as PIC, the linker optimizes R_386_GOT32X + * relocations to their fixed symbol addresses. However, when the + * compressed x86 kernel is loaded at a different address, it leads + * to the following load failure: + * + * Failed to allocate space for phdrs + * + * during the decompression stage. + * + * If the compressed x86 kernel is relocatable at run-time, it should be + * compiled with -fPIE, instead of -fPIC, if possible and should be built as + * Position Independent Executable (PIE) so that linker won't optimize + * R_386_GOT32X relocation to its fixed symbol address. Older + * linkers generate R_386_32 relocations against locally defined symbols, + * _bss, _ebss, _got and _egot, in PIE. It isn't wrong, just less + * optimal than R_386_RELATIVE. But the x86 kernel fails to properly handle + * R_386_32 relocations when relocating the kernel. To generate + * R_386_RELATIVE relocations, we mark _bss, _ebss, _got and _egot as + * hidden: + */ + .hidden _bss + .hidden _ebss + .hidden _got + .hidden _egot + __HEAD ENTRY(startup_32) #ifdef CONFIG_EFI_STUB
arch/x86/boot/compressed/head_64.S +8 -0
@@ -34,6 +34,14 @@ #include <asm/processor-flags.h> #include <asm/asm-offsets.h> +/* + * Locally defined symbols should be marked hidden: + */ + .hidden _bss + .hidden _ebss + .hidden _got + .hidden _egot + __HEAD .code32 ENTRY(startup_32)
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 51/319 x86/um: reuse asm-generic/barrier.h
In reply to Willy TarreauFrom: "Michael S. Tsirkin" <[email protected]>
commit 577f183acc88645eae116326cc2203dc88ea730c upstream.
On x86/um CONFIG_SMP is never defined. As a result, several macros match the asm-generic variant exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/x86/um/asm/barrier.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
arch/x86/um/asm/barrier.h +1 -5
@@ -51,11 +51,7 @@#else /* CONFIG_SMP */ -#define smp_mb () barrier() -#define smp_rmb () barrier() -#define smp_wmb () barrier() -#define smp_read_barrier_depends () do { } while (0) -#define set_mb (var, value) do { var = value; barrier(); } while (0) +#include <asm-generic/barrier.h> #endif /* CONFIG_SMP */
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 52/319 iommu/amd: Update Alias-DTE in update_device_table()
In reply to Willy TarreauFrom: Joerg Roedel <[email protected]>
commit 3254de6bf74fe94c197c9f819fe62a3a3c36f073 upstream.
Not doing so might cause IO-Page-Faults when a device uses an alias request-id and the alias-dte is left in a lower page-mode which does not cover the address allocated from the iova-allocator.
--- drivers/iommu/amd_iommu.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/iommu/amd_iommu.c +9 -1
@@ -2551,8 +2551,16 @@ static void update_device_table(struct protection_domain *domain) {struct iommu_dev_data *dev_data; -list_for_each_entry (dev_data, &domain->dev_list, list) +list_for_each_entry (dev_data, &domain->dev_list, list) {set_dte_entry (dev_data->devid, domain, dev_data->ats.enabled); + +if (dev_data->alias_data ==NULL ) +continue ; + +/* There is an alias, update device table entry for it */ +set_dte_entry (dev_data->alias_data->devid, domain, + dev_data->alias_data->ats.enabled); + } }static void update_domain (struct protection_domain *domain)
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 53/319 iommu/amd: Free domain id when free a domain of struct dma_ops_domain
In reply to Willy TarreauFrom: Baoquan He <[email protected]>
commit c3db901c54466a9c135d1e6e95fec452e8a42666 upstream.
The current code missed freeing domain id when free a domain of struct dma_ops_domain.
--- drivers/iommu/amd_iommu.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/iommu/amd_iommu.c +3 -0
@@ -1991,6 +1991,9 @@ static void dma_ops_domain_free(struct dma_ops_domain *dom)kfree (dom->aperture[i]); } +if (dom->domain.id) +domain_id_free (dom->domain.id); +kfree (dom); }
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 54/319 ARM: 8616/1: dt: Respect property size when parsing CPUs
In reply to Willy TarreauFrom: Robin Murphy <[email protected]>
commit ba6dea4f7cedb4b1c17e36f4087675d817c2e24b upstream.
Whilst MPIDR values themselves are less than 32 bits, it is still perfectly valid for a DT to have #address-cells > 1 in the CPUs node, resulting in the "reg" property having leading zero cell(s). In that situation, the big-endian nature of the data conspires with the current behaviour of only reading the first cell to cause the kernel to think all CPUs have ID 0, and become resoundingly unhappy as a consequence.
Take the full property length into account when parsing CPUs so as to be correct under any circumstances.
--- arch/arm/kernel/devtree.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
arch/arm/kernel/devtree.c +11 -3
@@ -90,6 +90,8 @@ void __init arm_dt_init_cpu_maps(void)return ;for_each_child_of_node (cpus, cpu) { +const __be32 *cell; +int prop_bytes;u32 hwid;if (of_node_cmp (cpu->type,"cpu" ))
@@ -101,17 +103,23 @@ void __init arm_dt_init_cpu_maps(void)* properties is considered invalid to build the * cpu_logical_map. */ -if (of_property_read_u32 (cpu,"reg" , &hwid)) { + cell =of_get_property (cpu,"reg" , &prop_bytes); +if (!cell || prop_bytes <sizeof (*cell)) {pr_debug (" * %s missing reg property\n" , cpu->full_name);return ; }/* -* 8 MSBs must be set to 0 in the DT since the reg property +* Bits n:24 must be set to 0 in the DT since the reg property * defines the MPIDR[23:0]. */ -if (hwid & ~MPIDR_HWID_BITMASK ) +do { + hwid =be32_to_cpu (*cell++); + prop_bytes -=sizeof (*cell); + }while (!hwid && prop_bytes >0 ); + +if (prop_bytes || (hwid & ~MPIDR_HWID_BITMASK ))return ;/*
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 55/319 ARM: 8618/1: decompressor: reset ttbcr fields to use TTBR0 on ARMv7
In reply to Willy TarreauFrom: Srinivas Ramana <[email protected]>
commit 117e5e9c4cfcb7628f08de074fbfefec1bb678b7 upstream.
If the bootloader uses the long descriptor format and jumps to kernel decompressor code, TTBCR may not be in a right state. Before enabling the MMU, it is required to clear the TTBCR.PD0 field to use TTBR0 for translation table walks.
The commit dbece45894d3a ("ARM: 7501/1: decompressor:
reset ttbcr for VMSA ARMv7 cores") does the reset of TTBCR.N, but doesn't consider all the bits for the size of TTBCR.N.
Clear TTBCR.PD0 field and reset all the three bits of TTBCR.N to indicate the use of TTBR0 and the correct base address width.
--- arch/arm/boot/compressed/head.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/compressed/head.S +1 -1
@@ -715,7 +715,7 @@ __armv7_mmu_cache_on: orrne r0, r0, #1 @ MMU enabled movne r1, #0xfffffffd @ domain 0 = client bic r6, r6, #1 << 31 @ 32-bit translation system - bic r6, r6, #3 << 0 @ use only ttbr0 + bic r6, r6, #(7 << 0) | (1 << 4) @ use only ttbr0 mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer mcrne p15, 0, r1, c3, c0, 0 @ load domain access control mcrne p15, 0, r6, c2, c0, 2 @ load ttb control
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 56/319 ARM: sa1100: clear reset status prior to reboot
In reply to Willy TarreauFrom: Russell King <[email protected]>
commit da60626e7d02a4f385cae80e450afc8b07035368 upstream.
Clear the current reset status prior to rebooting the platform. This adds the bit missing from 04fef228fb00 ("[ARM] pxa: introduce reset_status and clear_reset_status for driver's usage").
--- arch/arm/mach-sa1100/generic.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm/mach-sa1100/generic.c +2 -0
@@ -30,6 +30,7 @@#include <mach/hardware.h> #include <mach/irqs.h> +#include <mach/reset.h> #include "generic.h"
@@ -133,6 +134,7 @@ static void sa1100_power_off(void)void sa11x0_restart (char mode,const char *cmd) { +clear_reset_status (RESET_STATUS_ALL );if (mode =='s' ) {/* Jump into ROM at address 0 */ soft_restart (0 );
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 57/319 ARM: sa1111: fix pcmcia suspend/resume
In reply to Willy TarreauFrom: Russell King <[email protected]>
commit 06dfe5cc0cc684e735cb0232fdb756d30780b05d upstream.
SA1111 PCMCIA was broken when PCMCIA switched to using dev_pm_ops for the PCMCIA socket class. PCMCIA used to handle suspend/resume via the socket hosting device, which happened at normal device suspend/resume time.
However, the referenced commit changed this: much of the resume now happens much earlier, in the noirq resume handler of dev_pm_ops.
However, on SA1111, the PCMCIA device is not accessible as the SA1111 has not been resumed at _noirq time. It's slightly worse than that, because the SA1111 has already been put to sleep at _noirq time, so suspend doesn't work properly.
Fix this by converting the core SA1111 code to use dev_pm_ops as well, and performing its own suspend/resume at noirq time.
This fixes these errors in the kernel log:
pcmcia_socket pcmcia_socket0: time out after reset pcmcia_socket pcmcia_socket1: time out after reset
and the resulting lack of PCMCIA cards after a S2RAM cycle.
--- arch/arm/common/sa1111.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
arch/arm/common/sa1111.c +13 -9
@@ -872,9 +872,9 @@ struct sa1111_save_data {#ifdef CONFIG_PM -static int sa1111_suspend (struct platform_device *dev,pm_message_t state) +static int sa1111_suspend_noirq (struct device *dev) { -struct sa1111 *sachip =platform_get_drvdata (dev); +struct sa1111 *sachip =dev_get_drvdata (dev);struct sa1111_save_data *save;unsigned long flags;unsigned int val;
@@ -937,9 +937,9 @@ static int sa1111_suspend(struct platform_device *dev, pm_message_t state)* restored by their respective drivers, and must be called * via LDM after this function. */ -static int sa1111_resume (struct platform_device *dev) +static int sa1111_resume_noirq (struct device *dev) { -struct sa1111 *sachip =platform_get_drvdata (dev); +struct sa1111 *sachip =dev_get_drvdata (dev);struct sa1111_save_data *save;unsigned long flags, id;void __iomem *base;
@@ -955,7 +955,7 @@ static int sa1111_resume(struct platform_device *dev) id =sa1111_readl (sachip->base +SA1111_SKID );if ((id &SKID_ID_MASK ) !=SKID_SA1111_ID ) {__sa1111_remove (sachip); -platform_set_drvdata (dev,NULL ); +dev_set_drvdata (dev,NULL );kfree (save);return 0 ; }
@@ -1006,8 +1006,8 @@ static int sa1111_resume(struct platform_device *dev) }#else -#define sa1111_suspend NULL -#define sa1111_resume NULL +#define sa1111_suspend_noirq NULL +#define sa1111_resume_noirq NULL#endif static int sa1111_probe (struct platform_device *pdev)
@@ -1041,6 +1041,11 @@ static int sa1111_remove(struct platform_device *pdev)return 0 ; } +static struct dev_pm_ops sa1111_pm_ops = { + .suspend_noirq = sa1111_suspend_noirq, + .resume_noirq = sa1111_resume_noirq, +}; +/* * Not sure if this should be on the system bus or not yet. * We really want some way to register a system device at
@@ -1053,11 +1058,10 @@ static int sa1111_remove(struct platform_device *pdev)static struct platform_driver sa1111_device_driver = { .probe = sa1111_probe, .remove = sa1111_remove, - .suspend = sa1111_suspend, - .resume = sa1111_resume, .driver = { .name ="sa1111" , .owner =THIS_MODULE , + .pm = &sa1111_pm_ops, }, };
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 58/319 arm64: avoid returning from bad_mode
In reply to Willy TarreauFrom: Mark Rutland <[email protected]>
commit 7d9e8f71b989230bc613d121ca38507d34ada849 upstream.
Generally, taking an unexpected exception should be a fatal event, and bad_mode is intended to cater for this. However, it should be possible to contain unexpected synchronous exceptions from EL0 without bringing the kernel down, by sending a SIGILL to the task.
We tried to apply this approach in commit 9955ac47f4ba1c95 ("arm64:
don't kill the kernel on a bad esr from el0"), by sending a signal for any bad_mode call resulting from an EL0 exception.
However, this also applies to other unexpected exceptions, such as SError and FIQ. The entry paths for these exceptions branch to bad_mode without configuring the link register, and have no kernel_exit. Thus, if we take one of these exceptions from EL0, bad_mode will eventually return to the original user link register value.
This patch fixes this by introducing a new bad_el0_sync handler to cater for the recoverable case, and restoring bad_mode to its original state, whereby it calls panic() and never returns. The recoverable case branches to bad_el0_sync with a bl, and returns to userspace via the usual ret_to_user mechanism.
--- arch/arm64/kernel/entry.S | 2 +- arch/arm64/kernel/traps.c | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-)
arch/arm64/kernel/entry.S +1 -1
@@ -490,7 +490,7 @@ el0_inv: mov x0, sp mov x1, #BAD_SYNC mrs x2, esr_el1 - b bad_mode + b bad_el0_sync ENDPROC(el0_sync) .align 6
arch/arm64/kernel/traps.c +21 -4
@@ -307,16 +307,33 @@ asmlinkage long do_ni_syscall(struct pt_regs *regs) }/* -* bad_mode handles the impossible case in the exception vector. +* bad_mode handles the impossible case in the exception vector. This is always +* fatal. */ asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr) { -siginfo_t info; -void __user *pc = (void __user *)instruction_pointer (regs);console_verbose ();pr_crit ("Bad mode in %s handler detected, code 0x%08x\n" , handler[reason], esr); + +die ("Oops - bad mode" , regs,0 ); +local_irq_disable (); +panic ("bad mode" ); +} + +/* +* bad_el0_sync handles unexpected, but potentially recoverable synchronous +* exceptions taken from EL0. Unlike bad_mode, this returns. +*/ +asmlinkage void bad_el0_sync(struct pt_regs *regs, int reason, unsigned int esr) +{ +siginfo_t info; +void __user *pc = (void __user *)instruction_pointer (regs); +console_verbose (); + +pr_crit ("Bad EL0 synchronous exception detected on CPU%d, code 0x%08x\n" , +smp_processor_id (), esr);__show_regs (regs); info.si_signo =SIGILL ;
@@ -324,7 +341,7 @@ asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr) info.si_code =ILL_ILLOPC ; info.si_addr = pc; -arm64_notify_die ("Oops - bad mode" , regs, &info,0 ); +force_sig_info (info.si_signo, &info, current); }void __pte_error (const char *file,int line,unsigned long val)
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 59/319 arm64: Define AT_VECTOR_SIZE_ARCH for ARCH_DLINFO
In reply to Willy TarreauFrom: James Hogan <[email protected]>
commit 3146bc64d12377a74dbda12b96ea32da3774ae07 upstream.
AT_VECTOR_SIZE_ARCH should be defined with the maximum number of NEW_AUX_ENT entries that ARCH_DLINFO can contain, but it wasn't defined for arm64 at all even though ARCH_DLINFO will contain one NEW_AUX_ENT for the VDSO address.
This shouldn't be a problem as AT_VECTOR_SIZE_BASE includes space for AT_BASE_PLATFORM which arm64 doesn't use, but lets define it now and add the comment above ARCH_DLINFO as found in several other architectures to remind future modifiers of ARCH_DLINFO to keep AT_VECTOR_SIZE_ARCH up to date.
--- arch/arm64/include/asm/elf.h | 1 + arch/arm64/include/uapi/asm/auxvec.h | 2 ++ 2 files changed, 3 insertions(+)
arch/arm64/include/asm/elf.h +1 -0
@@ -126,6 +126,7 @@ extern unsigned long randomize_et_dyn(unsigned long base);#define SET_PERSONALITY (ex) clear_thread_flag(TIF_32BIT); +/* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */ #define ARCH_DLINFO \ do { \ NEW_AUX_ENT(AT_SYSINFO_EHDR, \
arch/arm64/include/uapi/asm/auxvec.h +2 -0
@@ -19,4 +19,6 @@/* vDSO location */ #define AT_SYSINFO_EHDR 33 +#define AT_VECTOR_SIZE_ARCH 1/* entries in ARCH_DLINFO */ +#endif
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 60/319 arm64: spinlocks: implement smp_mb__before_spinlock() as smp_mb()
In reply to Willy TarreauFrom: Will Deacon <[email protected]>
commit 872c63fbf9e153146b07f0cece4da0d70b283eeb upstream.
smp_mb__before_spinlock() is intended to upgrade a spin_lock() operation to a full barrier, such that prior stores are ordered with respect to loads and stores occuring inside the critical section.
Unfortunately, the core code defines the barrier as smp_wmb(), which is insufficient to provide the required ordering guarantees when used in conjunction with our load-acquire-based spinlock implementation.
This patch overrides the arm64 definition of smp_mb__before_spinlock() to map to a full smp_mb().
--- arch/arm64/include/asm/spinlock.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm64/include/asm/spinlock.h +10 -0
@@ -200,4 +200,14 @@ static inline int arch_read_trylock(arch_rwlock_t *rw)#define arch_read_relax (lock) cpu_relax()#define arch_write_relax (lock) cpu_relax() +/* +* Accesses appearing in program order before a spin_lock() operation +* can be reordered with accesses inside the critical section, by virtue +* of arch_spin_lock being constructed using acquire semantics. +* +* In cases where this is problematic (e.g. try_to_wake_up), an +* smp_mb__before_spinlock() can restore the required ordering. +*/ +#define smp_mb__before_spinlock () smp_mb() +#endif /* __ASM_SPINLOCK_H */
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 61/319 arm64: debug: avoid resetting stepping state machine when TIF_SINGLESTEP
In reply to Willy TarreauFrom: Will Deacon <[email protected]>
commit 3a402a709500c5a3faca2111668c33d96555e35a upstream.
When TIF_SINGLESTEP is set for a task, the single-step state machine is enabled and we must take care not to reset it to the active-not-pending state if it is already in the active-pending state.
Unfortunately, that's exactly what user_enable_single_step does, by unconditionally setting the SS bit in the SPSR for the current task. This causes failures in the GDB testsuite, where GDB ends up missing expected step traps if the instruction being stepped generates another trap, e.g. PTRACE_EVENT_FORK from an SVC instruction.
This patch fixes the problem by preserving the current state of the stepping state machine when TIF_SINGLESTEP is set on the current thread.
--- arch/arm64/kernel/debug-monitors.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm64/kernel/debug-monitors.c +4 -2
@@ -276,8 +276,10 @@ int kernel_active_single_step(void)/* ptrace API */ void user_enable_single_step (struct task_struct *task) { -set_ti_thread_flag (task_thread_info (task),TIF_SINGLESTEP ); -set_regs_spsr_ss (task_pt_regs (task)); +struct thread_info *ti =task_thread_info (task); + +if (!test_and_set_ti_thread_flag (ti,TIF_SINGLESTEP )) +set_regs_spsr_ss (task_pt_regs (task)); }void user_disable_single_step (struct task_struct *task)
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 62/319 MIPS: Malta: Fix IOCU disable switch read for MIPS64
In reply to Willy TarreauFrom: Paul Burton <[email protected]>
commit 305723ab439e14debc1d339aa04e835d488b8253 upstream.
Malta boards used with CPU emulators feature a switch to disable use of an IOCU. Software has to check this switch & ignore any present IOCU if the switch is closed. The read used to do this was unsafe for 64 bit kernels, as it simply casted the address 0xbf403000 to a pointer & dereferenced it. Whilst in a 32 bit kernel this would access kseg1, in a 64 bit kernel this attempts to access xuseg & results in an address error exception.
Fix by accessing a correctly formed ckseg1 address generated using the CKSEG1ADDR macro.
Whilst modifying this code, define the name of the register and the bit we care about within it, which indicates whether PCI DMA is routed to the IOCU or straight to DRAM. The code previously checked that bit 0 was also set, but the least significant 7 bits of the CONFIG_GEN0 register contain the value of the MReqInfo signal provided to the IOCU OCP bus, so singling out bit 0 makes little sense & that part of the check is dropped.
Patchwork: https://patchwork.linux-mips.org/patch/14187/
--- arch/mips/mti-malta/malta-setup.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/mips/mti-malta/malta-setup.c +7 -1
@@ -36,6 +36,9 @@#include <linux/console.h> #endif +#define ROCIT_CONFIG_GEN0 0x1f403000 +#define ROCIT_CONFIG_GEN0_PCI_IOCU BIT(7) +extern void malta_be_init (void );extern int malta_be_handler (struct pt_regs *regs,int is_fixup);
@@ -108,6 +111,8 @@ static void __init fd_activate(void)static int __init plat_enable_iocoherency (void ) {int supported =0 ; +u32 cfg; +if (mips_revision_sconid ==MIPS_REVISION_SCON_BONITO ) {if (BONITO_PCICACHECTRL &BONITO_PCICACHECTRL_CPUCOH_PRES ) {BONITO_PCICACHECTRL |=BONITO_PCICACHECTRL_CPUCOH_EN ;
@@ -130,7 +135,8 @@ static int __init plat_enable_iocoherency(void) }else if (gcmp_niocu () !=0 ) {/* Nothing special needs to be done to enable coherency */ pr_info ("CMP IOCU detected\n" ); -if ((*(unsigned int *)0xbf403000 &0x81 ) !=0x81 ) { + cfg =__raw_readl ((u32 *)CKSEG1ADDR (ROCIT_CONFIG_GEN0 )); +if (!(cfg &ROCIT_CONFIG_GEN0_PCI_IOCU )) {pr_crit ("IOCU OPERATION DISABLED BY SWITCH - DEFAULTING TO SW IO COHERENCY\n" );return 0 ; }
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 63/319 MIPS: ptrace: Fix regs_return_value for kernel context
In reply to Willy TarreauFrom: Marcin Nowakowski <[email protected]>
commit 74f1077b5b783e7bf4fa3007cefdc8dbd6c07518 upstream.
Currently regs_return_value always negates reg[2] if it determines the syscall has failed, but when called in kernel context this check is invalid and may result in returning a wrong value.
This fixes errors reported by CONFIG_KPROBES_SANITY_TEST
Patchwork: https://patchwork.linux-mips.org/patch/14381/
--- arch/mips/include/asm/ptrace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/include/asm/ptrace.h +1 -1
@@ -73,7 +73,7 @@ static inline int is_syscall_success(struct pt_regs *regs)static inline long regs_return_value (struct pt_regs *regs) { -if (is_syscall_success (regs)) +if (is_syscall_success (regs) || !user_mode (regs))return regs->regs[2 ];else return -regs->regs[2 ];
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 64/319 powerpc/mm: Don't alias user region to other regions below PAGE_OFFSET
In reply to Willy TarreauFrom: Paul Mackerras <[email protected]>
commit f077aaf0754bcba0fffdbd925bc12f09cd1e38aa upstream.
In commit c60ac5693c47 ("powerpc: Update kernel VSID range", 2013-03-13) we lost a check on the region number (the top four bits of the effective address) for addresses below PAGE_OFFSET. That commit replaced a check that the top 18 bits were all zero with a check that bits 46 - 59 were zero (performed for all addresses, not just user addresses).
This means that userspace can access an address like 0x1000_0xxx_xxxx_xxxx and we will insert a valid SLB entry for it. The VSID used will be the same as if the top 4 bits were 0, but the page size will be some random value obtained by indexing beyond the end of the mm_ctx_high_slices_psize array in the paca. If that page size is the same as would be used for region 0, then userspace just has an alias of the region 0 space. If the page size is different, then no HPTE will be found for the access, and the process will get a SIGSEGV (since hash_page_mm() will refuse to create a HPTE for the bogus address).
The access beyond the end of the mm_ctx_high_slices_psize can be at most 5.5MB past the array, and so will be in RAM somewhere. Since the access is a load performed in real mode, it won't fault or crash the kernel. At most this bug could perhaps leak a little bit of information about blocks of 32 bytes of memory located at offsets of i * 512kB past the paca->mm_ctx_high_slices_psize array, for 1 <= i <= 11.
--- arch/powerpc/mm/slb_low.S | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/powerpc/mm/slb_low.S +6 -1
@@ -110,7 +110,12 @@ BEGIN_FTR_SECTION END_MMU_FTR_SECTION_IFCLR(MMU_FTR_1T_SEGMENT) b slb_finish_load_1T -0: +0: /* + * For userspace addresses, make sure this is region 0. + */ + cmpdi r9, 0 + bne 8f + /* when using slices, we extract the psize off the slice bitmaps * and then we need to get the sllp encoding off the mmu_psize_defs * array.
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 65/319 powerpc/vdso64: Use double word compare on pointers
In reply to Willy TarreauFrom: Anton Blanchard <[email protected]>
commit 5045ea37377ce8cca6890d32b127ad6770e6dce5 upstream.
__kernel_get_syscall_map() and __kernel_clock_getres() use cmpli to check if the passed in pointer is non zero. cmpli maps to a 32 bit compare on binutils, so we ignore the top 32 bits.
A simple test case can be created by passing in a bogus pointer with the bottom 32 bits clear. Using a clk_id that is handled by the VDSO, then one that is handled by the kernel shows the problem:
printf("%d\n", clock_getres(CLOCK_REALTIME, (void *)0x100000000));
printf("%d\n", clock_getres(CLOCK_BOOTTIME, (void *)0x100000000));And we get:
0
-1
The bigger issue is if we pass a valid pointer with the bottom 32 bits clear, in this case we will return success but won't write any data to the pointer.
I stumbled across this issue because the LLVM integrated assembler doesn't accept cmpli with 3 arguments. Fix this by converting them to cmpldi.
--- arch/powerpc/kernel/vdso64/datapage.S | 2 +- arch/powerpc/kernel/vdso64/gettimeofday.S | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kernel/vdso64/datapage.S +1 -1
@@ -57,7 +57,7 @@ V_FUNCTION_BEGIN(__kernel_get_syscall_map) bl V_LOCAL_FUNC(__get_datapage) mtlr r12 addi r3,r3,CFG_SYSCALL_MAP64 - cmpli cr0,r4,0 + cmpldi cr0,r4,0 crclr cr0*4+so beqlr li r0,__NR_syscalls
arch/powerpc/kernel/vdso64/gettimeofday.S +1 -1
@@ -145,7 +145,7 @@ V_FUNCTION_BEGIN(__kernel_clock_getres) bne cr0,99f li r3,0 - cmpli cr0,r4,0 + cmpldi cr0,r4,0 crclr cr0*4+so beqlr lis r5,CLOCK_REALTIME_RES@h
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 66/319 powerpc/powernv: Use CPU-endian PEST in pnv_pci_dump_p7ioc_diag_data()
In reply to Willy TarreauFrom: Gavin Shan <[email protected]>
commit 5adaf8629b193f185ca5a1665b9e777a0579f518 upstream.
This fixes the warnings reported from sparse:
pci.c:312:33: warning: restricted __be64 degrades to integer pci.c:313:33: warning: restricted __be64 degrades to integer
--- arch/powerpc/platforms/powernv/pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/powernv/pci.c +2 -2
@@ -176,8 +176,8 @@ static void pnv_pci_dump_p7ioc_diag_data(struct pnv_phb *phb)pr_info (" dma1ErrorLog1 = 0x%016llx\n" , data->dma1ErrorLog1);for (i =0 ; i <OPAL_P7IOC_NUM_PEST_REGS ; i++) { -if ((data->pestA[i] >>63 ) ==0 && - (data->pestB[i] >>63 ) ==0 ) +if ((be64_to_cpu (data->pestA[i]) >>63 ) ==0 && + (be64_to_cpu (data->pestB[i]) >>63 ) ==0 )continue ;pr_info (" PE[%3d] PESTA = 0x%016llx\n" , i, data->pestA[i]);pr_info (" PESTB = 0x%016llx\n" , data->pestB[i]);
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 67/319 powerpc/64: Fix incorrect return value from __copy_tofrom_user
In reply to Willy TarreauFrom: Paul Mackerras <[email protected]>
commit 1a34439e5a0b2235e43f96816dbb15ee1154f656 upstream.
Debugging a data corruption issue with virtio-net/vhost-net led to the observation that __copy_tofrom_user was occasionally returning a value 16 larger than it should. Since the return value from __copy_tofrom_user is the number of bytes not copied, this means that __copy_tofrom_user can occasionally return a value larger than the number of bytes it was asked to copy. In turn this can cause higher-level copy functions such as copy_page_to_iter_iovec to corrupt memory by copying data into the wrong memory locations.
It turns out that the failing case involves a fault on the store at label 79, and at that point the first unmodified byte of the destination is at R3 + 16. Consequently the exception handler for that store needs to add 16 to R3 before using it to work out how many bytes were not copied, but in this one case it was not adding the offset to R3. To fix it, this moves the label 179 to the point where we add 16 to R3. I have checked manually all the exception handlers for the loads and stores in this code and the rest of them are correct (it would be excellent to have an automated test of all the exception cases).
This bug has been present since this code was initially committed in May 2002 to Linux version 2.5.20.
--- arch/powerpc/lib/copyuser_64.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/lib/copyuser_64.S +1 -1
@@ -336,6 +336,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_UNALIGNED_LD_STD) addi r3,r3,8 171: 177: +179: addi r3,r3,8 370: 372:
@@ -350,7 +351,6 @@ END_FTR_SECTION_IFCLR(CPU_FTR_UNALIGNED_LD_STD) 173: 174: 175: -179: 181: 184: 186:
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 68/319 powerpc/nvram: Fix an incorrect partition merge
In reply to Willy TarreauFrom: Pan Xinhui <[email protected]>
commit 11b7e154b132232535befe51c55db048069c8461 upstream.
When we merge two contiguous partitions whose signatures are marked NVRAM_SIG_FREE, We need update prev's length and checksum, then write it to nvram, not cur's. So lets fix this mistake now.
Also use memset instead of strncpy to set the partition's name. It's more readable if we want to fill up with duplicate chars .
--- arch/powerpc/kernel/nvram_64.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/kernel/nvram_64.c +3 -3
@@ -280,7 +280,7 @@ int __init nvram_remove_partition(const char *name, int sig,/* Make partition a free partition */ part->header.signature =NVRAM_SIG_FREE ; -strncpy (part->header.name,"wwwwwwwwwwww" ,12 ); +memset (part->header.name,'w' ,12 ); part->header.checksum =nvram_checksum (&part->header); rc =nvram_write_header (part);if (rc <=0 ) {
@@ -298,8 +298,8 @@ int __init nvram_remove_partition(const char *name, int sig, }if (prev) { prev->header.length += part->header.length; - prev->header.checksum =nvram_checksum (&part->header); - rc =nvram_write_header (part); + prev->header.checksum =nvram_checksum (&prev->header); + rc =nvram_write_header (prev);if (rc <=0 ) {printk (KERN_ERR "nvram_remove_partition: nvram_write failed (%d)\n" , rc);return rc;
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 69/319 avr32: fix copy_from_user()
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit 8630c32275bac2de6ffb8aea9d9b11663e7ad28e upstream.
really ugly, but apparently avr32 compilers turns access_ok() into something so bad that they want it in assembler. Left that way, zeroing added in inline wrapper.
--- arch/avr32/include/asm/uaccess.h | 11 ++++++++++- arch/avr32/kernel/avr32_ksyms.c | 2 +- arch/avr32/lib/copy_user.S | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-)
arch/avr32/include/asm/uaccess.h +10 -1
@@ -74,7 +74,7 @@ extern __kernel_size_t __copy_user(void *to, const void *from,extern __kernel_size_t copy_to_user (void __user *to,const void *from,__kernel_size_t n); -extern __kernel_size_t copy_from_user (void *to,const void __user *from, +extern __kernel_size_t ___copy_from_user (void *to,const void __user *from,__kernel_size_t n); static inline __kernel_size_t __copy_to_user(void __user *to, const void *from,
@@ -88,6 +88,15 @@ static inline __kernel_size_t __copy_from_user(void *to, {return __copy_user (to, (const void __force *)from, n); } +static inline __kernel_size_t copy_from_user (void *to, +const void __user *from, +__kernel_size_t n) +{ +size_t res =___copy_from_user (to, from, n); +if (unlikely (res)) +memset (to + (n - res),0 , res); +return res; +}#define __copy_to_user_inatomic __copy_to_user#define __copy_from_user_inatomic __copy_from_user
arch/avr32/kernel/avr32_ksyms.c +1 -1
@@ -36,7 +36,7 @@ EXPORT_SYMBOL(copy_page);/* * Userspace access stuff. */ -EXPORT_SYMBOL (copy_from_user); +EXPORT_SYMBOL (___copy_from_user);EXPORT_SYMBOL (copy_to_user);EXPORT_SYMBOL (__copy_user);EXPORT_SYMBOL (strncpy_from_user);
arch/avr32/lib/copy_user.S +2 -2
@@ -25,11 +25,11 @@ .align 1 .global copy_from_user .type copy_from_user, @function -copy_from_user: +___copy_from_user: branch_if_kernel r8, __copy_user ret_if_privileged r8, r11, r10, r10 rjmp __copy_user - .size copy_from_user, . - copy_from_user + .size ___copy_from_user, . - ___copy_from_user .global copy_to_user .type copy_to_user, @function
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 70/319 avr32: fix 'undefined reference to `___copy_from_user'
In reply to Willy TarreauFrom: Guenter Roeck <[email protected]>
commit 65c0044ca8d7c7bbccae37f0ff2972f0210e9f41 upstream.
avr32 builds fail with:
arch/avr32/kernel/built-in.o: In function `arch_ptrace':
(.text+0x650): undefined reference to ___copy_from_user' arch/avr32/kernel/built-in.o:(___ksymtab+___copy_from_user+0x0): undefined reference to ___copy_from_user'kernel/built-in.o: In function `proc_doulongvec_ms_jiffies_minmax':
(.text+0x5dd8): undefined reference to ___copy_from_user' kernel/built-in.o: In function proc_dointvec_minmax_sysadmin':
sysctl.c:(.text+0x6174): undefined reference to ___copy_from_user' kernel/built-in.o: In function ptrace_has_cap':
ptrace.c:(.text+0x69c0): undefined reference to ___copy_from_user' kernel/built-in.o:ptrace.c:(.text+0x6b90): more undefined references to ___copy_from_user' follow
--- arch/avr32/lib/copy_user.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/avr32/lib/copy_user.S +2 -2
@@ -23,8 +23,8 @@ */ .text .align 1 - .global copy_from_user - .type copy_from_user, @function + .global ___copy_from_user + .type ___copy_from_user, @function ___copy_from_user: branch_if_kernel r8, __copy_user ret_if_privileged r8, r11, r10, r10
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 71/319 avr32: off by one in at32_init_pio()
In reply to Willy TarreauFrom: Dan Carpenter <[email protected]>
commit 55f1cf83d5cf885c75267269729805852039c834 upstream.
The pio_dev[] array has MAX_NR_PIO_DEVICES elements so the > should be
Quoted 1 line
=.
--- arch/avr32/mach-at32ap/pio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/avr32/mach-at32ap/pio.c +1 -1
@@ -435,7 +435,7 @@ void __init at32_init_pio(struct platform_device *pdev)struct resource *regs;struct pio_device *pio; -if (pdev->id >MAX_NR_PIO_DEVICES ) { +if (pdev->id >=MAX_NR_PIO_DEVICES ) {dev_err (&pdev->dev,"only %d PIO devices supported\n" ,MAX_NR_PIO_DEVICES );return ;
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 72/319 s390/dasd: fix hanging device after clear subchannel
In reply to Willy TarreauFrom: Stefan Haberland <[email protected]>
commit 9ba333dc55cbb9523553df973adb3024d223e905 upstream.
When a device is in a status where CIO has killed all I/O by itself the interrupt for a clear request may not contain an irb to determine the clear function. Instead it contains an error pointer -EIO. This was ignored by the DASD int_handler leading to a hanging device waiting for a clear interrupt.
Handle -EIO error pointer correctly for requests that are clear pending and treat the clear as successful.
--- drivers/s390/block/dasd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/s390/block/dasd.c +9 -1
@@ -1615,9 +1615,18 @@ void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,unsigned long long now;int expires; + cqr = (struct dasd_ccw_req *) intparm;if (IS_ERR (irb)) {switch (PTR_ERR (irb)) {case -EIO : +if (cqr && cqr->status ==DASD_CQR_CLEAR_PENDING ) { + device = (struct dasd_device *) cqr->startdev; + cqr->status =DASD_CQR_CLEARED ; +dasd_device_clear_timer (device); +wake_up (&dasd_flush_wq); +dasd_schedule_device_bh (device); +return ; + }break ;case -ETIMEDOUT : DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
@@ -1633,7 +1642,6 @@ void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm, } now =get_tod_clock (); - cqr = (struct dasd_ccw_req *) intparm;/* check for conditions that should be handled immediately */ if (!cqr || !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 73/319 parisc: Ensure consistent state when switching to kernel stack at syscall entry
In reply to Willy TarreauFrom: John David Anglin <[email protected]>
commit 6ed518328d0189e0fdf1bb7c73290d546143ea66 upstream.
We have one critical section in the syscall entry path in which we switch from the userspace stack to kernel stack. In the event of an external interrupt, the interrupt code distinguishes between those two states by analyzing the value of sr7. If sr7 is zero, it uses the kernel stack. Therefore it's important, that the value of sr7 is in sync with the currently enabled stack.
This patch now disables interrupts while executing the critical section. This prevents the interrupt handler to possibly see an inconsistent state which in the worst case can lead to crashes.
Interestingly, in the syscall exit path interrupts were already disabled in the critical section which switches back to the userspace stack.
--- arch/parisc/kernel/syscall.S | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
arch/parisc/kernel/syscall.S +9 -2
@@ -106,8 +106,6 @@ linux_gateway_entry: mtsp %r0,%sr4 /* get kernel space into sr4 */ mtsp %r0,%sr5 /* get kernel space into sr5 */ mtsp %r0,%sr6 /* get kernel space into sr6 */ - mfsp %sr7,%r1 /* save user sr7 */ - mtsp %r1,%sr3 /* and store it in sr3 */ #ifdef CONFIG_64BIT /* for now we can *always* set the W bit on entry to the syscall
@@ -133,6 +131,14 @@ linux_gateway_entry: depdi 0, 31, 32, %r21 1: #endif + + /* We use a rsm/ssm pair to prevent sr3 from being clobbered + * by external interrupts. + */ + mfsp %sr7,%r1 /* save user sr7 */ + rsm PSW_SM_I, %r0 /* disable interrupts */ + mtsp %r1,%sr3 /* and store it in sr3 */ + mfctl %cr30,%r1 xor %r1,%r30,%r30 /* ye olde xor trick */ xor %r1,%r30,%r1
@@ -147,6 +153,7 @@ linux_gateway_entry: */ mtsp %r0,%sr7 /* get kernel space into sr7 */ + ssm PSW_SM_I, %r0 /* enable interrupts */ STREGM %r1,FRAME_SIZE(%r30) /* save r1 (usp) here for now */ mfctl %cr30,%r1 /* get task ptr in %r1 */ LDREG TI_TASK(%r1),%r1
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 74/319 microblaze: fix __get_user()
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit e98b9e37ae04562d52c96f46b3cf4c2e80222dc1 upstream.
--- arch/microblaze/include/asm/uaccess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/microblaze/include/asm/uaccess.h +1 -1
@@ -226,7 +226,7 @@ extern long __user_bad(void);#define __get_user (x, ptr) \ ({ \ - unsigned long __gu_val; \ + unsigned long __gu_val = 0; \/*unsigned long __gu_ptr = (unsigned long)(ptr);*/ \long __gu_err; \switch (sizeof (*(ptr))) { \
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 75/319 microblaze: fix copy_from_user()
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit d0cf385160c12abd109746cad1f13e3b3e8b50b8 upstream.
--- arch/microblaze/include/asm/uaccess.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/microblaze/include/asm/uaccess.h +6 -3
@@ -371,10 +371,13 @@ extern long __user_bad(void);static inline long copy_from_user (void *to,const void __user *from,unsigned long n) { +unsigned long res = n;might_sleep (); -if (access_ok (VERIFY_READ , from, n)) -return __copy_from_user (to, from, n); -return n; +if (likely (access_ok (VERIFY_READ , from, n))) + res =__copy_from_user (to, from, n); +if (unlikely (res)) +memset (to + (n - res),0 , res); +return res; }#define __copy_to_user (to, from, n) \
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 76/319 mn10300: failing __get_user() and get_user() should zero
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit 43403eabf558d2800b429cd886e996fd555aa542 upstream.
--- arch/mn10300/include/asm/uaccess.h | 1 + 1 file changed, 1 insertion(+)
arch/mn10300/include/asm/uaccess.h +1 -0
@@ -181,6 +181,7 @@ struct __large_struct { unsigned long buf[100]; };"2:\n" \" .section .fixup,\"ax\"\n" \"3:\n\t" \ +" mov 0,%1\n" \" mov %3,%0\n" \" jmp 2b\n" \" .previous\n" \
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 77/319 m32r: fix __get_user()
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit c90a3bc5061d57e7931a9b7ad14784e1a0ed497d upstream.
--- arch/m32r/include/asm/uaccess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/m32r/include/asm/uaccess.h +1 -1
@@ -215,7 +215,7 @@ extern int fixup_exception(struct pt_regs *regs);#define __get_user_nocheck (x,ptr,size) \ ({ \ long __gu_err = 0; \ - unsigned long __gu_val; \ + unsigned long __gu_val = 0; \ might_sleep(); \ __get_user_size(__gu_val,(ptr),(size),__gu_err); \ (x) = (__typeof__(*(ptr)))__gu_val; \
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 78/319 sh64: failing __get_user() should zero
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit c6852389228df9fb3067f94f3b651de2a7921b36 upstream.
It could be done in exception-handling bits in __get_user_b() et.al., but the surgery involved would take more knowledge of sh64 details than I have or _want_ to have.
--- arch/sh/include/asm/uaccess_64.h | 1 + 1 file changed, 1 insertion(+)
arch/sh/include/asm/uaccess_64.h +1 -0
@@ -24,6 +24,7 @@#define __get_user_size (x,ptr,size,retval) \ do { \ retval = 0; \ + x = 0; \ switch (size) { \ case 1: \ retval = __get_user_asm_b((void *)&x, \
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 79/319 score: fix __get_user/get_user
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit c2f18fa4cbb3ad92e033a24efa27583978ce9600 upstream.
* should zero on any failure
* __get_user() should use __copy_from_user(), not copy_from_user()
--- arch/score/include/asm/uaccess.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/score/include/asm/uaccess.h +4 -1
@@ -158,7 +158,7 @@ do { \__get_user_asm (val,"lw" , ptr); \break ; \case 8 : \ -if ((copy_from_user ((void *)&val, ptr,8 )) ==0 ) \ +if (__copy_from_user ((void *)&val, ptr,8 ) ==0 ) \ __gu_err =0 ; \else \ __gu_err = -EFAULT ; \
@@ -183,6 +183,8 @@ do { \ \if (likely (access_ok (VERIFY_READ , __gu_ptr, size))) \__get_user_common ((x), size, __gu_ptr); \ +else \ + (x) =0 ; \ \ __gu_err; \ })
@@ -196,6 +198,7 @@ do { \"2:\n" \".section .fixup,\"ax\"\n" \"3:li %0, %4\n" \ +"li %1, 0\n" \"j 2b\n" \".previous\n" \".section __ex_table,\"a\"\n" \
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 80/319 s390: get_user() should zero on failure
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit fd2d2b191fe75825c4c7a6f12f3fef35aaed7dd7 upstream.
--- arch/s390/include/asm/uaccess.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/s390/include/asm/uaccess.h +4 -4
@@ -164,28 +164,28 @@ extern int __put_user_bad(void) __attribute__((noreturn));__chk_user_ptr (ptr); \switch (sizeof (*(ptr))) { \case 1 : { \ -unsigned char __x; \ +unsigned char __x =0 ; \ __gu_err =__get_user_fn (sizeof (*(ptr)), \ ptr, &__x); \ (x) = *(__force __typeof__(*(ptr)) *) &__x; \break ; \ }; \case 2 : { \ -unsigned short __x; \ +unsigned short __x =0 ; \ __gu_err =__get_user_fn (sizeof (*(ptr)), \ ptr, &__x); \ (x) = *(__force __typeof__(*(ptr)) *) &__x; \break ; \ }; \case 4 : { \ -unsigned int __x; \ +unsigned int __x =0 ; \ __gu_err =__get_user_fn (sizeof (*(ptr)), \ ptr, &__x); \ (x) = *(__force __typeof__(*(ptr)) *) &__x; \break ; \ }; \case 8 : { \ -unsigned long long __x; \ +unsigned long long __x =0 ; \ __gu_err =__get_user_fn (sizeof (*(ptr)), \ ptr, &__x); \ (x) = *(__force __typeof__(*(ptr)) *) &__x; \
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 81/319 ARC: uaccess: get_user to zero out dest in cause of fault
In reply to Willy TarreauFrom: Vineet Gupta <[email protected]>
commit 05d9d0b96e53c52a113fd783c0c97c830c8dc7af upstream.
Al reported potential issue with ARC get_user() as it wasn't clearing out destination pointer in case of fault due to bad address etc.
Verified using following
| {
| u32 bogus1 = 0xdeadbeef;
| u64 bogus2 = 0xdead;
| int rc1, rc2;
|
| pr_info("Orig values %x %llx\n", bogus1, bogus2);
| rc1 = get_user(bogus1, (u32 __user *)0x40000000);
| rc2 = get_user(bogus2, (u64 __user *)0x50000000);
| pr_info("access %d %d, new values %x %llx\n",
| rc1, rc2, bogus1, bogus2);
| }| [ARCLinux]# insmod /mnt/kernel-module/qtn.ko | Orig values deadbeef dead | access -14 -14, new values 0 0
--- arch/arc/include/asm/uaccess.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
arch/arc/include/asm/uaccess.h +9 -2
@@ -83,7 +83,10 @@"2: ;nop\n" \" .section .fixup, \"ax\"\n" \" .align 4\n" \ -"3: mov %0, %3\n" \ +"3: # return -EFAULT\n" \ +" mov %0, %3\n" \ +" # zero out dst ptr\n" \ +" mov %1, 0\n" \" j 2b\n" \" .previous\n" \" .section __ex_table, \"a\"\n" \
@@ -101,7 +104,11 @@"2: ;nop\n" \" .section .fixup, \"ax\"\n" \" .align 4\n" \ -"3: mov %0, %3\n" \ +"3: # return -EFAULT\n" \ +" mov %0, %3\n" \ +" # zero out dst ptr\n" \ +" mov %1, 0\n" \ +" mov %R1, 0\n" \" j 2b\n" \" .previous\n" \" .section __ex_table, \"a\"\n" \
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 82/319 asm-generic: make get_user() clear the destination on errors
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit 9ad18b75c2f6e4a78ce204e79f37781f8815c0fa upstream.
both for access_ok() failures and for faults halfway through
--- include/asm-generic/uaccess.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
include/asm-generic/uaccess.h +7 -3
@@ -228,14 +228,18 @@ extern int __put_user_bad(void) __attribute__((noreturn));might_sleep (); \access_ok (VERIFY_READ , ptr,sizeof (*ptr)) ? \__get_user (x, ptr) : \ - -EFAULT ; \ + ((x) = (__typeof__ (*(ptr )))0 ,-EFAULT ); \ })#ifndef __get_user_fnstatic inline int __get_user_fn (size_t size,const void __user *ptr,void *x) { - size =__copy_from_user (x, ptr, size); -return size ? -EFAULT : size; +size_t n =__copy_from_user (x, ptr, size); +if (unlikely (n)) { +memset (x + (size - n),0 , n); +return -EFAULT ; + } +return 0 ; }#define __get_user_fn (sz, u, k) __get_user_fn(sz, u, k)
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 83/319 frv: fix clear_user()
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit 3b8767a8f00cc6538ba6b1cf0f88502e2fd2eb90 upstream.
It should check access_ok(). Otherwise a bunch of places turn into trivially exploitable rootholes.
--- arch/frv/include/asm/uaccess.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
arch/frv/include/asm/uaccess.h +9 -3
@@ -263,19 +263,25 @@ do { \extern long __memset_user (void *dst,unsigned long count);extern long __memcpy_user (void *dst,const void *src,unsigned long count); -#define clear_user (dst,count) __memset_user(____force(dst), (count)) +#define __clear_user (dst,count) __memset_user(____force(dst), (count))#define __copy_from_user_inatomic (to, from, n) __memcpy_user((to), ____force(from), (n))#define __copy_to_user_inatomic (to, from, n) __memcpy_user(____force(to), (from), (n))#else -#define clear_user (dst,count) (memset(____force(dst), 0, (count)), 0) +#define __clear_user (dst,count) (memset(____force(dst), 0, (count)), 0)#define __copy_from_user_inatomic (to, from, n) (memcpy((to), ____force(from), (n)), 0)#define __copy_to_user_inatomic (to, from, n) (memcpy(____force(to), (from), (n)), 0)#endif -#define __clear_user clear_user +static inline unsigned long __must_check +clear_user (void __user *to,unsigned long n) +{ +if (likely (__access_ok (to, n))) + n =__clear_user (to, n); +return n; +}static inline unsigned long __must_check __copy_to_user (void __user *to,const void *from,unsigned long n)
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 84/319 cris: buggered copy_from_user/copy_to_user/clear_user
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit eb47e0293baaa3044022059f1fa9ff474bfe35cb upstream.
* copy_from_user() on access_ok() failure ought to zero the destination
* none of those primitives should skip the access_ok() check in case of small constant size.
--- arch/cris/include/asm/uaccess.h | 71 +++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 39 deletions(-)
arch/cris/include/asm/uaccess.h +32 -39
@@ -176,30 +176,6 @@ extern unsigned long __copy_user(void __user *to, const void *from, unsigned lonextern unsigned long __copy_user_zeroing (void *to,const void __user *from,unsigned long n);extern unsigned long __do_clear_user (void __user *to,unsigned long n); -static inline unsigned long -__generic_copy_to_user (void __user *to,const void *from,unsigned long n) -{ -if (access_ok (VERIFY_WRITE , to, n)) -return __copy_user (to,from,n); -return n; -} - -static inline unsigned long -__generic_copy_from_user (void *to,const void __user *from,unsigned long n) -{ -if (access_ok (VERIFY_READ , from, n)) -return __copy_user_zeroing (to,from,n); -return n; -} - -static inline unsigned long -__generic_clear_user (void __user *to,unsigned long n) -{ -if (access_ok (VERIFY_WRITE , to, n)) -return __do_clear_user (to,n); -return n; -} -static inline long __strncpy_from_user (char *dst,const char __user *src,long count) {
@@ -262,7 +238,7 @@ __constant_copy_from_user(void *to, const void __user *from, unsigned long n)else if (n ==24 )__asm_copy_from_user_24 (to, from, ret);else - ret =__generic_copy_from_user (to, from, n); + ret =__copy_user_zeroing (to, from, n);return ret; }
@@ -312,7 +288,7 @@ __constant_copy_to_user(void __user *to, const void *from, unsigned long n)else if (n ==24 )__asm_copy_to_user_24 (to, from, ret);else - ret =__generic_copy_to_user (to, from, n); + ret =__copy_user (to, from, n);return ret; }
@@ -344,26 +320,43 @@ __constant_clear_user(void __user *to, unsigned long n)else if (n ==24 )__asm_clear_24 (to, ret);else - ret =__generic_clear_user (to, n); + ret =__do_clear_user (to, n);return ret; } -#define clear_user (to, n) \ -(__builtin_constant_p(n) ? \ - __constant_clear_user(to, n) : \ - __generic_clear_user(to, n)) +static inline size_t clear_user (void __user *to,size_t n) +{ +if (unlikely (!access_ok (VERIFY_WRITE , to, n))) +return n; +if (__builtin_constant_p (n)) +return __constant_clear_user (to, n); +else +return __do_clear_user (to, n); +} -#define copy_from_user (to, from, n) \ -(__builtin_constant_p(n) ? \ - __constant_copy_from_user(to, from, n) : \ - __generic_copy_from_user(to, from, n)) +static inline size_t copy_from_user (void *to,const void __user *from,size_t n) +{ +if (unlikely (!access_ok (VERIFY_READ , from, n))) { +memset (to,0 , n); +return n; + } +if (__builtin_constant_p (n)) +return __constant_copy_from_user (to, from, n); +else +return __copy_user_zeroing (to, from, n); +} -#define copy_to_user (to, from, n) \ -(__builtin_constant_p(n) ? \ - __constant_copy_to_user(to, from, n) : \ - __generic_copy_to_user(to, from, n)) +static inline size_t copy_to_user (void __user *to,const void *from,size_t n) +{ +if (unlikely (!access_ok (VERIFY_WRITE , to, n))) +return n; +if (__builtin_constant_p (n)) +return __constant_copy_to_user (to, from, n); +else +return __copy_user (to, from, n); +}/* We let the __ versions of copy_from/to_user inline, because they're often * used in fast paths and have only a small space overhead.
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 85/319 blackfin: fix copy_from_user()
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit 8f035983dd826d7e04f67b28acf8e2f08c347e41 upstream.
--- arch/blackfin/include/asm/uaccess.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
arch/blackfin/include/asm/uaccess.h +5 -4
@@ -177,11 +177,12 @@ static inline int bad_user_access_length(void)static inline unsigned long __must_check copy_from_user (void *to,const void __user *from,unsigned long n) { -if (access_ok (VERIFY_READ , from, n)) +if (likely (access_ok (VERIFY_READ , from, n))) {memcpy (to, (const void __force *)from, n); -else -return n; -return 0 ; +return 0 ; + } +memset (to,0 , n); +return n; } static inline unsigned long __must_check
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 86/319 score: fix copy_from_user() and friends
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit b615e3c74621e06cd97f86373ca90d43d6d998aa upstream.
--- arch/score/include/asm/uaccess.h | 41 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 21 deletions(-)
arch/score/include/asm/uaccess.h +20 -21
@@ -296,35 +296,34 @@ extern int __copy_tofrom_user(void *to, const void *from, unsigned long len);static inline unsigned long copy_from_user (void *to,const void *from,unsigned long len) { -unsigned long over; +unsigned long res = len; -if (access_ok (VERIFY_READ , from, len)) -return __copy_tofrom_user (to, from, len); +if (likely (access_ok (VERIFY_READ , from, len))) + res =__copy_tofrom_user (to, from, len); -if ((unsigned long )from <TASK_SIZE ) { - over = (unsigned long )from + len -TASK_SIZE ; -return __copy_tofrom_user (to, from, len - over) + over; - } -return len; +if (unlikely (res)) +memset (to + (len - res),0 , res); + +return res; }static inline unsigned long copy_to_user (void *to,const void *from,unsigned long len) { -unsigned long over; - -if (access_ok (VERIFY_WRITE , to, len)) -return __copy_tofrom_user (to, from, len); +if (likely (access_ok (VERIFY_WRITE , to, len))) + len =__copy_tofrom_user (to, from, len); -if ((unsigned long )to <TASK_SIZE ) { - over = (unsigned long )to + len -TASK_SIZE ; -return __copy_tofrom_user (to, from, len - over) + over; - }return len; } -#define __copy_from_user (to, from, len) \ - __copy_tofrom_user((to), (from), (len)) +static inline unsigned long +__copy_from_user (void *to,const void *from,unsigned long len) +{ +unsigned long left =__copy_tofrom_user (to, from, len); +if (unlikely (left)) +memset (to + (len - left),0 , left); +return left; +}#define __copy_to_user (to, from, len) \ __copy_tofrom_user((to), (from), (len))
@@ -338,17 +337,17 @@ __copy_to_user_inatomic(void *to, const void *from, unsigned long len)static inline unsigned long __copy_from_user_inatomic (void *to,const void *from,unsigned long len) { -return __copy_from_user (to, from, len); +return __copy_tofrom_user (to, from, len); } -#define __copy_in_user (to, from, len) __copy_from_user(to, from, len) +#define __copy_in_user (to, from, len) __copy_tofrom_user(to, from, len)static inline unsigned long copy_in_user (void *to,const void *from,unsigned long len) {if (access_ok (VERIFY_READ , from, len) &&access_ok (VERFITY_WRITE , to, len)) -return copy_from_user (to, from, len); +return __copy_tofrom_user (to, from, len); }/*
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 87/319 sh: fix copy_from_user()
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit 6e050503a150b2126620c1a1e9b3a368fcd51eac upstream.
--- arch/sh/include/asm/uaccess.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/sh/include/asm/uaccess.h +4 -1
@@ -151,7 +151,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)__kernel_size_t __copy_size = (__kernel_size_t ) n;if (__copy_size &&__access_ok (__copy_from, __copy_size)) -return __copy_user (to, from, __copy_size); + __copy_size =__copy_user (to, from, __copy_size); + +if (unlikely (__copy_size)) +memset (to + (n - __copy_size),0 , __copy_size);return __copy_size; }
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 88/319 hexagon: fix strncpy_from_user() error return
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit f35c1e0671728d1c9abc405d05ef548b5fcb2fc4 upstream.
It's -EFAULT, not -1 (and contrary to the comment in there, __strnlen_user() can return 0 - on faults).
--- arch/hexagon/include/asm/uaccess.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/hexagon/include/asm/uaccess.h +2 -1
@@ -102,7 +102,8 @@ static inline long hexagon_strncpy_from_user(char *dst, const char __user *src, {long res =__strnlen_user (src, n); -/* return from strnlen can't be zero -- that would be rubbish. */ +if (unlikely (!res)) +return -EFAULT ;if (res > n) {copy_from_user (dst, src, n);
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 89/319 mips: copy_from_user() must zero the destination on access_ok() failure
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit e69d700535ac43a18032b3c399c69bf4639e89a2 upstream.
--- arch/mips/include/asm/uaccess.h | 3 +++ 1 file changed, 3 insertions(+)
arch/mips/include/asm/uaccess.h +3 -0
@@ -13,6 +13,7 @@#include <linux/kernel.h> #include <linux/errno.h> #include <linux/thread_info.h> +#include <linux/string.h> /* * The fs value determines whether argument validity checking should be
@@ -938,6 +939,8 @@ extern size_t __copy_user_inatomic(void *__to, const void *__from, size_t __n);might_fault (); \ __cu_len =__invoke_copy_from_user (__cu_to, __cu_from, \ __cu_len); \ + }else { \ +memset (__cu_to,0 , __cu_len); \ } \ __cu_len; \ })
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 90/319 asm-generic: make copy_from_user() zero the destination properly
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit 2545e5da080b4839dd859e3b09343a884f6ab0e3 upstream.
... in all cases, including the failing access_ok()
Note that some architectures using asm-generic/uaccess.h have __copy_from_user() not zeroing the tail on failure halfway through. This variant works either way.
--- include/asm-generic/uaccess.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
include/asm-generic/uaccess.h +6 -4
@@ -259,11 +259,13 @@ extern int __get_user_bad(void) __attribute__((noreturn));static inline long copy_from_user (void *to,const void __user * from,unsigned long n) { +unsigned long res = n;might_sleep (); -if (access_ok (VERIFY_READ , from, n)) -return __copy_from_user (to, from, n); -else -return n; +if (likely (access_ok (VERIFY_READ , from, n))) + res =__copy_from_user (to, from, n); +if (unlikely (res)) +memset (to + (n - res),0 , res); +return res; } static inline long copy_to_user(void __user *to,
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 91/319 alpha: fix copy_from_user()
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit 2561d309dfd1555e781484af757ed0115035ddb3 upstream.
it should clear the destination even when access_ok() fails.
--- arch/alpha/include/asm/uaccess.h | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
arch/alpha/include/asm/uaccess.h +8 -11
@@ -371,14 +371,6 @@ __copy_tofrom_user_nocheck(void *to, const void *from, long len)return __cu_len; } -extern inline long -__copy_tofrom_user (void *to,const void *from,long len,const void __user *validate) -{ -if (__access_ok ((unsigned long )validate, len,get_fs ())) - len =__copy_tofrom_user_nocheck (to, from, len); -return len; -} -#define __copy_to_user (to,from,n) \ ({ \ __chk_user_ptr(to); \
@@ -393,17 +385,22 @@ __copy_tofrom_user(void *to, const void *from, long len, const void __user *vali#define __copy_to_user_inatomic __copy_to_user#define __copy_from_user_inatomic __copy_from_user -extern inline long copy_to_user (void __user *to,const void *from,long n) { -return __copy_tofrom_user ((__force void *)to, from, n, to); +if (likely (__access_ok ((unsigned long )to, n,get_fs ()))) + n =__copy_tofrom_user_nocheck ((__force void *)to, from, n); +return n; }extern inline long copy_from_user (void *to,const void __user *from,long n) { -return __copy_tofrom_user (to, (__force void *)from, n, from); +if (likely (__access_ok ((unsigned long )from, n,get_fs ()))) + n =__copy_tofrom_user_nocheck (to, (__force void *)from, n); +else +memset (to,0 , n); +return n; }extern void __do_clear_user (void );
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 92/319 metag: copy_from_user() should zero the destination on access_ok() failure
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit 8ae95ed4ae5fc7c3391ed668b2014c9e2079533b upstream.
--- arch/metag/include/asm/uaccess.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/metag/include/asm/uaccess.h +2 -1
@@ -199,8 +199,9 @@ extern unsigned long __must_check __copy_user_zeroing(void *to,static inline unsigned long copy_from_user (void *to,const void __user *from,unsigned long n) { -if (access_ok (VERIFY_READ , from, n)) +if (likely (access_ok (VERIFY_READ , from, n)))return __copy_user_zeroing (to, from, n); +memset (to,0 , n);return n; }
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 93/319 parisc: fix copy_from_user()
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit aace880feea38875fbc919761b77e5732a3659ef upstream.
--- arch/parisc/include/asm/uaccess.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/parisc/include/asm/uaccess.h +5 -2
@@ -9,6 +9,8 @@#include <asm/errno.h> #include <asm-generic/uaccess-unaligned.h> +#include <linux/string.h> +#define VERIFY_READ 0#define VERIFY_WRITE 1
@@ -246,13 +248,14 @@ static inline unsigned long __must_check copy_from_user(void *to, unsigned long n) {int sz =__compiletime_object_size (to); -int ret = -EFAULT ; +unsigned long ret = n;if (likely (sz ==-1 || !__builtin_constant_p (n) || sz >= n)) ret =__copy_from_user (to, from, n);else copy_from_user_overflow (); - +if (unlikely (ret)) +memset (to + (n - ret),0 , ret);return ret; }
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 94/319 openrisc: fix copy_from_user()
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit acb2505d0119033a80c85ac8d02dccae41271667 upstream.
... that should zero on faults. Also remove the <censored> helpful logics wrt range truncation copied from ppc32. Where it had ever been needed only in case of copy_from_user() *and* had not been merged into the mainline until a month after the need had disappeared. A decade before openrisc went into mainline, I might add...
--- arch/openrisc/include/asm/uaccess.h | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-)
arch/openrisc/include/asm/uaccess.h +11 -24
@@ -273,28 +273,20 @@ __copy_tofrom_user(void *to, const void *from, unsigned long size);static inline unsigned long copy_from_user (void *to,const void *from,unsigned long n) { -unsigned long over; - -if (access_ok (VERIFY_READ , from, n)) -return __copy_tofrom_user (to, from, n); -if ((unsigned long )from <TASK_SIZE ) { - over = (unsigned long )from + n -TASK_SIZE ; -return __copy_tofrom_user (to, from, n - over) + over; - } -return n; +unsigned long res = n; + +if (likely (access_ok (VERIFY_READ , from, n))) + n =__copy_tofrom_user (to, from, n); +if (unlikely (res)) +memset (to + (n - res),0 , res); +return res; }static inline unsigned long copy_to_user (void *to,const void *from,unsigned long n) { -unsigned long over; - -if (access_ok (VERIFY_WRITE , to, n)) -return __copy_tofrom_user (to, from, n); -if ((unsigned long )to <TASK_SIZE ) { - over = (unsigned long )to + n -TASK_SIZE ; -return __copy_tofrom_user (to, from, n - over) + over; - } +if (likely (access_ok (VERIFY_WRITE , to, n))) + n =__copy_tofrom_user (to, from, n);return n; }
@@ -303,13 +295,8 @@ extern unsigned long __clear_user(void *addr, unsigned long size);static inline __must_check unsigned long clear_user (void *addr,unsigned long size) { - -if (access_ok (VERIFY_WRITE , addr, size)) -return __clear_user (addr, size); -if ((unsigned long )addr <TASK_SIZE ) { -unsigned long over = (unsigned long )addr + size -TASK_SIZE ; -return __clear_user (addr, size - over) + over; - } +if (likely (access_ok (VERIFY_WRITE , addr, size))) + size =__clear_user (addr, size);return size; }
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 95/319 openrisc: fix the fix of copy_from_user()
In reply to Willy TarreauFrom: Guenter Roeck <[email protected]>
commit 8e4b72054f554967827e18be1de0e8122e6efc04 upstream.
Since commit acb2505d0119 ("openrisc: fix copy_from_user()"), copy_from_user() returns the number of bytes requested, not the number of bytes not copied.
--- arch/openrisc/include/asm/uaccess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/openrisc/include/asm/uaccess.h +1 -1
@@ -276,7 +276,7 @@ copy_from_user(void *to, const void *from, unsigned long n)unsigned long res = n;if (likely (access_ok (VERIFY_READ , from, n))) - n =__copy_tofrom_user (to, from, n); + res =__copy_tofrom_user (to, from, n);if (unlikely (res))memset (to + (n - res),0 , res);return res;
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 96/319 mn10300: copy_from_user() should zero on access_ok() failure...
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit ae7cc577ec2a4a6151c9e928fd1f595d953ecef1 upstream.
--- arch/mn10300/lib/usercopy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/mn10300/lib/usercopy.c +3 -1
@@ -9,7 +9,7 @@* as published by the Free Software Foundation; either version * 2 of the Licence, or (at your option) any later version. */ -#include <asm/uaccess.h> +#include <linux/uaccess.h> unsigned long __generic_copy_to_user (void *to,const void *from,unsigned long n)
@@ -24,6 +24,8 @@ __generic_copy_from_user(void *to, const void *from, unsigned long n) {if (access_ok (VERIFY_READ , from, n))__copy_user_zeroing (to, from, n); +else +memset (to,0 , n);return n; }
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 97/319 sparc32: fix copy_from_user()
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit 917400cecb4b52b5cde5417348322bb9c8272fa6 upstream.
--- arch/sparc/include/asm/uaccess_32.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/sparc/include/asm/uaccess_32.h +3 -1
@@ -265,8 +265,10 @@ static inline unsigned long copy_from_user(void *to, const void __user *from, un {if (n &&__access_ok ((unsigned long ) from, n))return __copy_user ((__force void __user *) to, from, n); -else +else { +memset (to,0 , n);return n; + } }static inline unsigned long __copy_from_user (void *to,const void __user *from,unsigned long n)
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 98/319 ppc32: fix copy_from_user()
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit 224264657b8b228f949b42346e09ed8c90136a8e upstream.
should clear on access_ok() failures. Also remove the useless range truncation logics.
--- arch/powerpc/include/asm/uaccess.h | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-)
arch/powerpc/include/asm/uaccess.h +2 -19
@@ -323,30 +323,17 @@ extern unsigned long __copy_tofrom_user(void __user *to,static inline unsigned long copy_from_user (void *to,const void __user *from,unsigned long n) { -unsigned long over; - -if (access_ok (VERIFY_READ , from, n)) +if (likely (access_ok (VERIFY_READ , from, n)))return __copy_tofrom_user ((__force void __user *)to, from, n); -if ((unsigned long )from <TASK_SIZE ) { - over = (unsigned long )from + n -TASK_SIZE ; -return __copy_tofrom_user ((__force void __user *)to, from, - n - over) + over; - } +memset (to,0 , n);return n; }static inline unsigned long copy_to_user (void __user *to,const void *from,unsigned long n) { -unsigned long over; -if (access_ok (VERIFY_WRITE , to, n))return __copy_tofrom_user (to, (__force void __user *)from, n); -if ((unsigned long )to <TASK_SIZE ) { - over = (unsigned long )to + n -TASK_SIZE ; -return __copy_tofrom_user (to, (__force void __user *)from, - n - over) + over; - }return n; }
@@ -437,10 +424,6 @@ static inline unsigned long clear_user(void __user *addr, unsigned long size)might_sleep ();if (likely (access_ok (VERIFY_WRITE , addr, size)))return __clear_user (addr, size); -if ((unsigned long )addr <TASK_SIZE ) { -unsigned long over = (unsigned long )addr + size -TASK_SIZE ; -return __clear_user (addr, size - over) + over; - }return size; }
Signature · 1 line
2.8.0.rc2.1.gbe9624a
PATCH 99/319 ia64: copy_from_user() should zero the destination on access_ok() failure
In reply to Willy TarreauFrom: Al Viro <[email protected]>
commit a5e541f796f17228793694d64b507f5f57db4cd7 upstream.
--- arch/ia64/include/asm/uaccess.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
arch/ia64/include/asm/uaccess.h +9 -11
@@ -262,17 +262,15 @@ __copy_from_user (void *to, const void __user *from, unsigned long count) __cu_len; \ }) -#define copy_from_user (to, from, n) \ -({ \ - void *__cu_to = (to); \ - const void __user *__cu_from = (from); \ - long __cu_len = (n); \ - \ - __chk_user_ptr(__cu_from); \ - if (__access_ok(__cu_from, __cu_len, get_fs())) \ - __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \ - __cu_len; \ -}) +static inline unsigned long +copy_from_user (void *to,const void __user *from,unsigned long n) +{ +if (likely (__access_ok (from, n,get_fs ()))) + n =__copy_user ((__force void __user *) to, from, n); +else +memset (to,0 , n); +return n; +}#define __copy_in_user (to, from, size) __copy_user((to), (from), (size))
Signature · 1 line
2.8.0.rc2.1.gbe9624a